#!/usr/bin/env python3 """Update and validate the repository's single release version source.""" import argparse from pathlib import Path import re VERSION_FILE = Path("VERSION") CHART_FILE = Path("deploy/helm/ai-spel-static/Chart.yaml") SEMVER = re.compile(r"^(\d+)\.(\d+)\.(\d+)$") def read_version() -> str: version = VERSION_FILE.read_text().strip() if not SEMVER.fullmatch(version): raise SystemExit(f"Invalid semantic version in {VERSION_FILE}: {version}") return version def check(version: str) -> None: chart = CHART_FILE.read_text() chart_version = re.findall(r"(?m)^version:\s*(\S+)\s*$", chart) app_version = re.findall(r'(?m)^appVersion:\s*"(\S+)"\s*$', chart) if chart_version != [version] or app_version != [version]: raise SystemExit( f"Version drift: VERSION={version}, chart version={chart_version}, " f"appVersion={app_version}" ) def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--check", action="store_true") args = parser.parse_args() current = read_version() check(current) if args.check: print(current) return major, minor, patch = map(int, current.split(".")) next_version = f"{major}.{minor}.{patch + 1}" chart = CHART_FILE.read_text() chart = re.sub(r"(?m)^version:\s*" + re.escape(current) + r"\s*$", f"version: {next_version}", chart, count=1) chart = re.sub(r'(?m)^appVersion:\s*"' + re.escape(current) + r'"\s*$', f'appVersion: "{next_version}"', chart, count=1) VERSION_FILE.write_text(f"{next_version}\n") CHART_FILE.write_text(chart) print(next_version) if __name__ == "__main__": main()