Files
ObsiGate/backend/version.py
T
bruno a80df670be
CI / lint (push) Failing after 9s
CI / test (push) Has been skipped
CI / build (push) Has been skipped
CI / e2e (push) Has been skipped
CI / security (push) Successful in 17s
Desktop Build / build-windows (push) Has been cancelled
Desktop Build / build-linux (push) Has been cancelled
fix: version Docker — générer VERSION file depuis .git/HEAD au build
- Dockerfile: COPY .git/HEAD + .git/refs/ → génère backend/VERSION avec hash
- version.py: fallback lit backend/VERSION (à côté du module, pas racine repo)
- Format: 1.8.0-0-g<8-char-hash> ou 1.8.0-dev si indisponible
2026-07-27 17:17:47 -04:00

65 lines
1.9 KiB
Python

"""
Version management for ObsiGate.
Uses git describe to generate a SemVer-compatible version string.
Format: MAJOR.MINOR.PATCH[-commits-since-tag-gHASH]
Examples:
v1.7.0 (exact tag)
v1.7.0-3-gabc1234 (3 commits after v1.7.0)
v1.7.0-dev (fallback when Git unavailable)
"""
from __future__ import annotations
import subprocess
from pathlib import Path
_ROOT = Path(__file__).resolve().parent.parent # ObsiGate repo root
def get_version() -> str:
"""Get the current version from Git tags."""
try:
result = subprocess.run(
["git", "describe", "--tags", "--dirty=-dirty"],
cwd=str(_ROOT),
capture_output=True,
text=True,
timeout=5,
)
if result.returncode == 0:
tag = result.stdout.strip()
# git describe returns v1.7.0 or v1.7.0-3-gabc1234
# Remove leading 'v' if present
if tag.startswith("v"):
tag = tag[1:]
return tag
except (FileNotFoundError, subprocess.TimeoutExpired, OSError):
pass
# Fallback: try reading from a VERSION file next to this module
version_file = Path(__file__).parent / "VERSION"
if version_file.exists():
return version_file.read_text().strip()
return "0.0.0-dev"
def get_version_tuple() -> tuple[int, int, int]:
"""Return (major, minor, patch) tuple for programmatic use."""
raw = get_version()
# Strip -suffix for parsing
base = raw.split("-")[0]
try:
parts = base.split(".")
major = int(parts[0]) if len(parts) > 0 else 0
minor = int(parts[1]) if len(parts) > 1 else 0
patch = int(parts[2]) if len(parts) > 2 else 0
return (major, minor, patch)
except (ValueError, IndexError):
return (0, 0, 0)
if __name__ == "__main__":
print(get_version())