Ajout d'une gestion conditionnelle de la version applicative avec mise à jour ou lecture depuis VERSION.txt selon le mode (DEV/PROD).
This commit is contained in:
parent
a5c1aa06a5
commit
b3f201dd8d
1 changed files with 39 additions and 10 deletions
|
|
@ -158,15 +158,44 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
# On défini une fonction qui va s'occuper de récupérer la version actuelle de l'application
|
# On défini une fonction qui va s'occuper de récupérer la version actuelle de l'application
|
||||||
def get_git_version():
|
def get_git_version():
|
||||||
try:
|
|
||||||
import subprocess
|
import subprocess
|
||||||
hash_version = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8')
|
"""
|
||||||
app_version = subprocess.check_output(
|
DEV : Calcule la version Git et met à jour le fichier VERSION.txt
|
||||||
["git", "describe", "--tags", "--abbrev=0"],
|
PROD : Lit simplement le fichier VERSION.txt
|
||||||
stderr=subprocess.STDOUT
|
"""
|
||||||
).strip().decode('utf-8')
|
version_file = os.path.join(BASE_DIR, 'VERSION.txt')
|
||||||
return app_version + " (" + hash_version + ")"
|
|
||||||
except Exception:
|
# --- CAS 1 : MODE DÉVELOPPEMENT (Mise à jour du fichier) ---
|
||||||
return 'Dev / Pas de git'
|
if DEBUG:
|
||||||
|
try:
|
||||||
|
# 1. On récupère les infos Git
|
||||||
|
hash_part = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'],
|
||||||
|
stderr=subprocess.DEVNULL).strip().decode('utf-8')
|
||||||
|
|
||||||
|
try:
|
||||||
|
tag_part = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"],
|
||||||
|
stderr=subprocess.DEVNULL).strip().decode('utf-8')
|
||||||
|
except:
|
||||||
|
tag_part = "v0.0.x" # Fallback si pas de tag
|
||||||
|
|
||||||
|
full_version = f"{tag_part} ({hash_part})"
|
||||||
|
|
||||||
|
# 2. On ÉCRIT/MET À JOUR le fichier texte
|
||||||
|
with open(version_file, 'w') as f:
|
||||||
|
f.write(full_version)
|
||||||
|
|
||||||
|
return full_version
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
# Si Git échoue en local (rare, mais possible)
|
||||||
|
return f"Dev Mode (Err: {e})"
|
||||||
|
|
||||||
|
# --- CAS 2 : MODE PRODUCTION (Lecture seule) ---
|
||||||
|
else:
|
||||||
|
if os.path.exists(version_file):
|
||||||
|
with open(version_file, 'r') as f:
|
||||||
|
return f.read().strip()
|
||||||
|
else:
|
||||||
|
return "Version inconnue (Fichier manquant)"
|
||||||
|
|
||||||
GIT_VERSION = get_git_version()
|
GIT_VERSION = get_git_version()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue