|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import sys |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +def bump_pyproject(version: str) -> None: |
| 6 | + try: |
| 7 | + import tomlkit # type: ignore |
| 8 | + except Exception as e: |
| 9 | + print("tomlkit not available; please install tomlkit", file=sys.stderr) |
| 10 | + raise |
| 11 | + |
| 12 | + p = Path("pyproject.toml") |
| 13 | + if not p.exists(): |
| 14 | + return |
| 15 | + data = tomlkit.parse(p.read_text(encoding="utf-8")) |
| 16 | + if "project" in data and isinstance(data["project"], dict): |
| 17 | + data["project"]["version"] = version |
| 18 | + p.write_text(tomlkit.dumps(data), encoding="utf-8") |
| 19 | + |
| 20 | +def bump_chart_yaml(version: str) -> None: |
| 21 | + try: |
| 22 | + import yaml # type: ignore |
| 23 | + except Exception as e: |
| 24 | + print("pyyaml not available; please install pyyaml", file=sys.stderr) |
| 25 | + raise |
| 26 | + |
| 27 | + chart = Path("charts/discord-rag-bot/Chart.yaml") |
| 28 | + if not chart.exists(): |
| 29 | + return |
| 30 | + data = yaml.safe_load(chart.read_text(encoding="utf-8")) or {} |
| 31 | + data["version"] = str(version) |
| 32 | + data["appVersion"] = str(version) |
| 33 | + chart.write_text(yaml.safe_dump(data, sort_keys=False), encoding="utf-8") |
| 34 | + |
| 35 | +def main() -> int: |
| 36 | + if len(sys.argv) < 2: |
| 37 | + print("Usage: bump_version.py <version>", file=sys.stderr) |
| 38 | + return 2 |
| 39 | + version = sys.argv[1] |
| 40 | + bump_pyproject(version) |
| 41 | + bump_chart_yaml(version) |
| 42 | + print(f"Bumped versions to {version}") |
| 43 | + return 0 |
| 44 | + |
| 45 | +if __name__ == "__main__": |
| 46 | + raise SystemExit(main()) |
| 47 | + |
0 commit comments