gmao/app_new/core/build_info.py
root 518d31c891
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
Afficher le commit dans le setup
2026-08-21 22:21:17 +00:00

33 lines
999 B
Python

"""Informations sur le build actuellement exécuté."""
import os
import subprocess
from pathlib import Path
def get_build_commit():
"""Retourne l'identifiant du commit déployé.
En production, le dépôt Git n'est pas forcément présent dans l'image :
les variables d'environnement sont donc prioritaires. Le fallback Git
permet de conserver un affichage utile en développement.
"""
for variable in ("GIT_COMMIT", "COMMIT_SHA", "SOURCE_VERSION"):
value = (os.environ.get(variable) or "").strip()
if value:
return value
repository = Path(__file__).resolve().parents[2]
try:
result = subprocess.run(
["git", "rev-parse", "HEAD"],
cwd=repository,
check=True,
capture_output=True,
text=True,
timeout=1,
)
except (OSError, subprocess.SubprocessError):
return "inconnu"
commit = result.stdout.strip()
return commit or "inconnu"