From 9e45ea8870322e082eba13a223d1a85b256696d7 Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 21 Jul 2026 07:58:24 -0400 Subject: [PATCH] feat: version dynamique via fichier VERSION MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fichier VERSION à la racine (4.0.3) - _get_app_version() avec cache dans dashboard.py - Lecture depuis VERSION (dev) ou /app/VERSION (Docker) - Fallback '0.0.0' si fichier absent - board.py: import _get_app_version depuis dashboard - Les deux _sidebar_data() remplacent '4.0.3' par _get_app_version() - Déploiement: changer VERSION → mettre à jour sans toucher le code - 143 tests passent --- VERSION | 1 + app/routers/board.py | 3 ++- app/routers/dashboard.py | 28 +++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..c4e41f9 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +4.0.3 diff --git a/app/routers/board.py b/app/routers/board.py index 3a3de30..eefdbef 100644 --- a/app/routers/board.py +++ b/app/routers/board.py @@ -10,6 +10,7 @@ from fastapi.responses import HTMLResponse, JSONResponse from app.db import get_conn from app.services.gitea_client import gitea from app.auth.session import SessionManager +from app.routers.dashboard import _get_app_version logger = logging.getLogger(__name__) router = APIRouter(tags=["board"], prefix="/board") @@ -397,7 +398,7 @@ def _sidebar_data(request: Request, owner: str = "", repo: str = "") -> dict: "gitea_linked": gitea_linked, "github_linked": github_linked, "has_active_workspace": has_active_workspace, - "app_version": "4.0.3", + "app_version": _get_app_version(), "local_workspaces": _local_workspaces_for_user(user)} diff --git a/app/routers/dashboard.py b/app/routers/dashboard.py index 4cc4072..48e45ec 100644 --- a/app/routers/dashboard.py +++ b/app/routers/dashboard.py @@ -13,6 +13,32 @@ from app.db import get_conn logger = logging.getLogger(__name__) router = APIRouter(tags=["dashboard"]) +_VERSION = None + + +def _get_app_version() -> str: + """Read version from VERSION file with caching.""" + global _VERSION + if _VERSION is not None: + return _VERSION + try: + import os + version_path = os.path.join(os.path.dirname(__file__), "..", "..", "VERSION") + if os.path.exists(version_path): + with open(version_path) as f: + _VERSION = f.read().strip() + else: + # Docker fallback + version_path = "/app/VERSION" + if os.path.exists(version_path): + with open(version_path) as f: + _VERSION = f.read().strip() + else: + _VERSION = "0.0.0" + except Exception: + _VERSION = "0.0.0" + return _VERSION + def _get_user_or_redirect(request: Request): """Return decoded user or a RedirectResponse to login page. @@ -188,7 +214,7 @@ def _sidebar_data(request: Request, repos: list[dict], include_workspace: bool = "gitea_linked": gitea_linked, "github_linked": github_linked, "has_active_workspace": has_active_workspace, - "app_version": "4.0.3", + "app_version": _get_app_version(), } sidebar["local_workspaces"] = _local_workspaces_for_user(user)