feat: Add branch info to version display and update checker

- version.py now captures and exports GIT_BRANCH
- Display branch badge next to version in menu (e.g., "2026.01.20+abc1234 [dev]")
- /api/version now returns branch field
- /api/check-update uses frozen branch instead of hardcoded "dev"
- Allows proper update checking for both dev and main branches

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-01-20 21:00:11 +01:00
parent f36c2eb3c8
commit 7c78bef906
4 changed files with 45 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ from flask_socketio import SocketIO, emit
from app.config import config, runtime_config
from app.routes.views import views_bp
from app.routes.api import api_bp
from app.version import VERSION_STRING
from app.version import VERSION_STRING, GIT_BRANCH
from app.archiver.manager import schedule_daily_archiving
from app.meshcore.cli import fetch_device_name_from_bridge
@@ -44,10 +44,10 @@ def create_app():
app.config['DEBUG'] = config.FLASK_DEBUG
app.config['SECRET_KEY'] = 'mc-webui-secret-key-change-in-production'
# Inject version into all templates
# Inject version and branch into all templates
@app.context_processor
def inject_version():
return {'version': VERSION_STRING}
return {'version': VERSION_STRING, 'git_branch': GIT_BRANCH}
# Register blueprints
app.register_blueprint(views_bp)

View File

@@ -1989,20 +1989,21 @@ def get_version():
{
"success": true,
"version": "2025.01.18+576c8ca9",
"docker_tag": "2025.01.18-576c8ca9"
"docker_tag": "2025.01.18-576c8ca9",
"branch": "dev"
}
"""
from app.version import VERSION_STRING, DOCKER_TAG
from app.version import VERSION_STRING, DOCKER_TAG, GIT_BRANCH
return jsonify({
'success': True,
'version': VERSION_STRING,
'docker_tag': DOCKER_TAG
'docker_tag': DOCKER_TAG,
'branch': GIT_BRANCH
}), 200
# GitHub repository for update checks
GITHUB_REPO = "MarekWo/mc-webui"
GITHUB_BRANCH = "dev" # Check updates against dev branch
@api_bp.route('/check-update', methods=['GET'])
@@ -2011,9 +2012,10 @@ def check_update():
Check if a newer version is available on GitHub.
Compares current commit hash with latest commit on GitHub.
Uses the branch from frozen version (dev/main) automatically.
Query parameters:
branch (str): Branch to check (default: dev)
branch (str): Branch to check (default: from frozen version)
Returns:
JSON with update status:
@@ -2022,16 +2024,18 @@ def check_update():
"update_available": true,
"current_version": "2026.01.18+abc1234",
"current_commit": "abc1234",
"current_branch": "dev",
"latest_commit": "def5678",
"latest_date": "2026.01.20",
"latest_message": "feat: New feature",
"github_url": "https://github.com/MarekWo/mc-webui/commits/dev"
}
"""
from app.version import VERSION_STRING
from app.version import VERSION_STRING, GIT_BRANCH
try:
branch = request.args.get('branch', GITHUB_BRANCH)
# Use branch from frozen version, or allow override via query param
branch = request.args.get('branch', GIT_BRANCH)
# Extract current commit hash from VERSION_STRING (format: YYYY.MM.DD+hash or YYYY.MM.DD+hash+dirty)
current_commit = None
@@ -2093,6 +2097,7 @@ def check_update():
'update_available': update_available,
'current_version': VERSION_STRING,
'current_commit': current_commit[:7],
'current_branch': branch,
'latest_commit': latest_commit,
'latest_date': latest_date,
'latest_message': latest_message,

View File

@@ -61,6 +61,7 @@
<div class="px-3 pb-2 text-muted small border-bottom d-flex align-items-center justify-content-between">
<span id="versionDisplay">
<i class="bi bi-tag"></i> <span id="versionText">{{ version }}</span>
<span class="badge bg-secondary ms-1" id="branchBadge">{{ git_branch }}</span>
</span>
<button id="checkUpdateBtn" class="btn btn-sm btn-outline-secondary py-0 px-1" title="Check for updates">
<i class="bi bi-arrow-repeat" id="checkUpdateIcon"></i>

View File

@@ -8,6 +8,7 @@ import os
VERSION_STRING = "0.0.0+unknown"
DOCKER_TAG = "0.0.0-unknown"
GIT_BRANCH = "unknown"
def subprocess_run(args):
@@ -24,6 +25,24 @@ def subprocess_run(args):
return proc.stdout.strip()
def get_git_branch():
"""Get current git branch name."""
try:
# Try to get branch name
branch = subprocess_run("git rev-parse --abbrev-ref HEAD")
if branch == "HEAD":
# Detached HEAD state - try to get branch from remote
branch = subprocess_run("git branch -r --contains HEAD")
if branch:
# Parse "origin/branch" format
branch = branch.split("/")[-1].split("\n")[0].strip()
else:
branch = "detached"
return branch
except subprocess.CalledProcessError:
return "unknown"
def get_git_version():
"""Get version from git commit date and hash."""
# Get date (YYYY.MM.DD) and short hash
@@ -40,15 +59,18 @@ def get_git_version():
if e.returncode == 1:
git_version += "+dirty"
return git_version, docker_tag
# Get branch name
git_branch = get_git_branch()
return git_version, docker_tag, git_branch
# Load version: frozen file takes priority, then git, then fallback
try:
from app.version_frozen import VERSION_STRING, DOCKER_TAG
from app.version_frozen import VERSION_STRING, DOCKER_TAG, GIT_BRANCH
except ImportError:
try:
VERSION_STRING, DOCKER_TAG = get_git_version()
VERSION_STRING, DOCKER_TAG, GIT_BRANCH = get_git_version()
except Exception:
pass # Keep defaults
@@ -56,15 +78,17 @@ except ImportError:
if __name__ == "__main__":
import sys
if len(sys.argv) >= 2 and sys.argv[1] == "freeze":
VERSION_STRING, DOCKER_TAG = get_git_version()
VERSION_STRING, DOCKER_TAG, GIT_BRANCH = get_git_version()
code = f'''"""Frozen version - auto-generated, do not edit."""
VERSION_STRING = "{VERSION_STRING}"
DOCKER_TAG = "{DOCKER_TAG}"
GIT_BRANCH = "{GIT_BRANCH}"
'''
path = os.path.join(os.path.dirname(__file__), "version_frozen.py")
with open(path, "w", encoding="utf8") as f:
f.write(code)
print(f"Version frozen: {VERSION_STRING}")
print(f"Version frozen: {VERSION_STRING} ({GIT_BRANCH})")
else:
print(f'VERSION_STRING="{VERSION_STRING}"')
print(f'DOCKER_TAG="{DOCKER_TAG}"')
print(f'GIT_BRANCH="{GIT_BRANCH}"')