feat(evidencia): versión 0.2.0 desde APP_VERSION o el último tag
El manifiesto toma la versión de APP_VERSION, del último tag de git o de pyproject.toml, que sube a 0.2.0.
This commit is contained in:
1 parent
09bda933c9
commit
681bc033ae
4 files changed
+42
-17
No files matched your search
+22
-14
@@ -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 ---------------------------------
|
||||
|
||||
+1
-1
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user