|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import re |
| 4 | +import sys |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | + |
| 8 | +_VER_RE = re.compile(r"^\d+\.\d+\.\d+$") |
| 9 | + |
| 10 | + |
| 11 | +def _replace_line(text: str, pattern: re.Pattern[str], replacement: str) -> str: |
| 12 | + new_text, n = pattern.subn(replacement, text, count=1) |
| 13 | + if n != 1: |
| 14 | + raise RuntimeError(f"No se pudo actualizar: patron={pattern.pattern!r}") |
| 15 | + return new_text |
| 16 | + |
| 17 | + |
| 18 | +def _apply_app_version_py(repo_root: Path, version: str) -> None: |
| 19 | + path = repo_root / "app" / "version.py" |
| 20 | + text = path.read_text(encoding="utf-8") |
| 21 | + text = _replace_line( |
| 22 | + text, |
| 23 | + re.compile(r'^__version__\s*=\s*".*?"\s*$', re.MULTILINE), |
| 24 | + f'__version__ = "{version}"', |
| 25 | + ) |
| 26 | + path.write_text(text, encoding="utf-8") |
| 27 | + |
| 28 | + |
| 29 | +def _apply_inno_iss(repo_root: Path, version: str) -> None: |
| 30 | + path = repo_root / "Yagua.iss" |
| 31 | + text = path.read_text(encoding="utf-8") |
| 32 | + text = _replace_line( |
| 33 | + text, |
| 34 | + re.compile(r"^AppVersion=.*$", re.MULTILINE), |
| 35 | + f"AppVersion={version}", |
| 36 | + ) |
| 37 | + text = _replace_line( |
| 38 | + text, |
| 39 | + re.compile(r"^AppVerName=.*$", re.MULTILINE), |
| 40 | + f"AppVerName=Yagua {version}", |
| 41 | + ) |
| 42 | + text = _replace_line( |
| 43 | + text, |
| 44 | + re.compile(r"^OutputBaseFilename=.*$", re.MULTILINE), |
| 45 | + f"OutputBaseFilename=Yagua_Setup_{version}", |
| 46 | + ) |
| 47 | + path.write_text(text, encoding="utf-8") |
| 48 | + |
| 49 | + |
| 50 | +def main(argv: list[str]) -> int: |
| 51 | + if len(argv) != 2: |
| 52 | + print("Uso: python scripts/ci/apply_version.py <X.Y.Z>", file=sys.stderr) |
| 53 | + return 2 |
| 54 | + |
| 55 | + version = argv[1].strip() |
| 56 | + if not _VER_RE.match(version): |
| 57 | + print(f"Version invalida: {version!r} (esperado X.Y.Z)", file=sys.stderr) |
| 58 | + return 2 |
| 59 | + |
| 60 | + repo_root = Path(__file__).resolve().parents[2] |
| 61 | + _apply_app_version_py(repo_root, version) |
| 62 | + _apply_inno_iss(repo_root, version) |
| 63 | + print(f"OK: version aplicada = {version}") |
| 64 | + return 0 |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + raise SystemExit(main(sys.argv)) |
| 69 | + |
0 commit comments