Afficher le commit dans le setup
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run

This commit is contained in:
root 2026-08-21 22:21:17 +00:00
parent d58b5aed0b
commit 518d31c891
5 changed files with 69 additions and 1 deletions

View file

@ -63,6 +63,12 @@ def create_app(config_name='default'):
app.config.from_object(config_class)
config_class.init_app(app)
# Affiché notamment dans le setup wizard afin d'identifier sans ambiguïté
# le code réellement exécuté par un conteneur, même avant installation.
from .core.build_info import get_build_commit
app.config['GIT_COMMIT'] = get_build_commit()
app.context_processor(lambda: {'build_commit': app.config['GIT_COMMIT']})
# Initialisation des extensions
db.init_app(app)
login_manager.init_app(app)

View file

@ -0,0 +1,33 @@
"""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"

View file

@ -6,6 +6,7 @@
<div class="card shadow mx-auto" style="max-width: 1200px">
<div class="card-header bg-primary text-white">
<h4 class="mb-0"><i class="bi bi-gear-fill"></i> Configuration initiale GMAO</h4>
<div class="small mt-1 opacity-75">Commit déployé : <code class="text-white">{{ build_commit }}</code></div>
</div>
<div class="card-body">
<div class="d-flex flex-wrap justify-content-between gap-2 mb-4" id="stepIndicators">

View file

@ -10,6 +10,7 @@
<i class="bi bi-check-circle-fill text-success" style="font-size: 4rem;"></i>
<h2 class="mt-4">Configuration terminée</h2>
<p class="text-muted">Le système GMAO a déjà été configuré.</p>
<p class="small text-muted mb-0">Commit déployé : <code>{{ build_commit }}</code></p>
<a href="{{ url_for('companies.index') }}" class="btn btn-primary mt-3">
<i class="bi bi-house"></i> Accueil
</a>

View file

@ -1,6 +1,33 @@
from pathlib import Path
def test_build_commit_prefers_deployment_environment(monkeypatch):
from app_new.core.build_info import get_build_commit
monkeypatch.setenv('GIT_COMMIT', 'commit-deploye-test')
monkeypatch.setenv('COMMIT_SHA', 'autre-commit')
assert get_build_commit() == 'commit-deploye-test'
def test_setup_pages_display_build_commit(client, monkeypatch, tmp_path):
from app_new.core.routes import setup_wizard
monkeypatch.setattr(setup_wizard, 'DATA_DIR', str(tmp_path))
monkeypatch.setenv('GIT_COMMIT', 'commit-visible-test')
client.application.config['GIT_COMMIT'] = 'commit-visible-test'
token = 'test-setup-token-with-at-least-32-characters'
response = client.get(f'/setup-wizard/?token={token}')
assert response.status_code == 302
response = client.get('/setup-wizard/')
assert b'commit-visible-test' in response.data
Path(tmp_path, '.setup_complete').write_text('complete', encoding='utf-8')
response = client.get('/setup-wizard/')
assert response.status_code == 200
assert b'commit-visible-test' in response.data
def test_login_page_does_not_disclose_demo_passwords(client):
response = client.get('/auth/login')
assert response.status_code == 200