From 681bc033ae046865c915ebad9858c6fb110b9503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorem=20Ju=C3=A1rez?= Date: Thu, 8 Oct 2026 09:29:49 -0600 Subject: [PATCH] =?UTF-8?q?feat(evidencia):=20versi=C3=B3n=200.2.0=20desde?= =?UTF-8?q?=20APP=5FVERSION=20o=20el=20=C3=BAltimo=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit El manifiesto toma la versión de APP_VERSION, del último tag de git o de pyproject.toml, que sube a 0.2.0. --- app/services/evidencia.py | 36 ++++++++++++++++++++++-------------- pyproject.toml | 2 +- tests/test_evidencia.py | 17 +++++++++++++++++ uv.lock | 4 ++-- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/app/services/evidencia.py b/app/services/evidencia.py index 00a40dc..a02eabd 100644 --- a/app/services/evidencia.py +++ b/app/services/evidencia.py @@ -61,22 +61,30 @@ def nombre_archivo(id_externo: str, fecha: date) -> str: return f"evidencia_{id_externo}_{fecha.isoformat()}.zip" -def version_sistema() -> dict[str, str | None]: - """Versión del paquete y sha de git del código que corre. +def _git(*argumentos: str) -> str | None: + try: + salida = subprocess.run( + ["git", *argumentos], cwd=RAIZ, capture_output=True, text=True, timeout=5, + check=True, + ).stdout.strip() # fmt: skip + except (OSError, subprocess.SubprocessError): + return None + return salida or None - En el contenedor no hay `.git`: Coolify expone el commit desplegado en `SOURCE_COMMIT` - (también se acepta `GIT_SHA`). En local se pregunta a git. Si nada responde, `None`. + +def version_sistema() -> dict[str, str | None]: + """Versión y sha de git del código que corre. + + - Versión: `APP_VERSION` (la fija el despliegue, p. ej. `v0.2.0`); si no, el último tag de + git (`git describe --tags --abbrev=0`); si no, la del paquete (`pyproject.toml`). + - Sha: en el contenedor no hay `.git`; Coolify expone el commit desplegado en + `SOURCE_COMMIT` (también se acepta `GIT_SHA`). En local se pregunta a git. """ - sha = os.environ.get("SOURCE_COMMIT") or os.environ.get("GIT_SHA") - if not sha: - try: - sha = subprocess.run( - ["git", "rev-parse", "HEAD"], cwd=RAIZ, capture_output=True, text=True, - timeout=5, check=True, - ).stdout.strip() # fmt: skip - except (OSError, subprocess.SubprocessError): - sha = None - return {"version": __version__, "git_sha": sha or None} + version = ( + os.environ.get("APP_VERSION") or _git("describe", "--tags", "--abbrev=0") or __version__ + ) + sha = os.environ.get("SOURCE_COMMIT") or os.environ.get("GIT_SHA") or _git("rev-parse", "HEAD") + return {"version": version, "git_sha": sha} # --- Archivos referidos: nombre y hash, nunca el contenido --------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 53c5257..565f7f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "collina-pld" -version = "0.0.1" +version = "0.2.0" description = "Prototipo de plataforma PLD/FT para CHM Compliance (Collina)" readme = "README.md" requires-python = ">=3.12" diff --git a/tests/test_evidencia.py b/tests/test_evidencia.py index 7c76f49..a22407e 100644 --- a/tests/test_evidencia.py +++ b/tests/test_evidencia.py @@ -160,6 +160,23 @@ def test_a_una_fecha_anterior_solo_va_lo_que_existia( assert _filas(zip_, "audit_trail.csv") == [] +def test_la_version_viene_de_app_version_o_del_ultimo_tag( + monkeypatch: pytest.MonkeyPatch, +) -> None: + from app.services import evidencia + + monkeypatch.setenv("APP_VERSION", "v9.9.9") + monkeypatch.setenv("SOURCE_COMMIT", "abc123") + assert evidencia.version_sistema() == {"version": "v9.9.9", "git_sha": "abc123"} + + monkeypatch.delenv("APP_VERSION") + monkeypatch.setattr(evidencia, "_git", lambda *a: "v0.2.0" if a[0] == "describe" else None) + assert evidencia.version_sistema()["version"] == "v0.2.0" + + monkeypatch.setattr(evidencia, "_git", lambda *a: None) + assert evidencia.version_sistema()["version"] == "0.2.0" # pyproject.toml + + def test_el_nombre_del_archivo() -> None: from datetime import date diff --git a/uv.lock b/uv.lock index b6690ce..3e79353 100644 --- a/uv.lock +++ b/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 5 +revision = 3 requires-python = ">=3.12" [[package]] @@ -67,7 +67,7 @@ wheels = [ [[package]] name = "collina-pld" -version = "0.0.1" +version = "0.2.0" source = { editable = "." } dependencies = [ { name = "alembic" },