|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Update diracx-charts with a new diracx-web version. |
| 3 | +
|
| 4 | +Bumps the chart version and updates the web image tag in values.yaml. |
| 5 | +Does NOT modify appVersion (that tracks the diracx server version). |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +import argparse |
| 11 | +import re |
| 12 | +import sys |
| 13 | +from pathlib import Path |
| 14 | + |
| 15 | + |
| 16 | +def bump_version(current_version: str) -> str: |
| 17 | + """Bump a version: increment alpha number if present, otherwise patch.""" |
| 18 | + match = re.match( |
| 19 | + r"^(\d+\.\d+\.\d+)-alpha\.(\d+)$", current_version |
| 20 | + ) |
| 21 | + if match: |
| 22 | + base, alpha = match.group(1), int(match.group(2)) |
| 23 | + return f"{base}-alpha.{alpha + 1}" |
| 24 | + |
| 25 | + match = re.match(r"^(\d+)\.(\d+)\.(\d+)$", current_version) |
| 26 | + if match: |
| 27 | + major, minor, patch = match.groups() |
| 28 | + return f"{major}.{minor}.{int(patch) + 1}" |
| 29 | + |
| 30 | + raise ValueError(f"Invalid version format: {current_version}") |
| 31 | + |
| 32 | + |
| 33 | +def main() -> None: |
| 34 | + parser = argparse.ArgumentParser( |
| 35 | + description="Update diracx-charts for a new diracx-web release" |
| 36 | + ) |
| 37 | + parser.add_argument( |
| 38 | + "--charts-dir", |
| 39 | + type=Path, |
| 40 | + required=True, |
| 41 | + help="Path to the diracx-charts repository", |
| 42 | + ) |
| 43 | + parser.add_argument( |
| 44 | + "--web-version", |
| 45 | + required=True, |
| 46 | + help="New diracx-web version (e.g., v0.1.0)", |
| 47 | + ) |
| 48 | + args = parser.parse_args() |
| 49 | + |
| 50 | + chart_yaml = args.charts_dir / "diracx" / "Chart.yaml" |
| 51 | + values_yaml = args.charts_dir / "diracx" / "values.yaml" |
| 52 | + |
| 53 | + for path in (chart_yaml, values_yaml): |
| 54 | + if not path.exists(): |
| 55 | + print(f"Error: {path} not found") |
| 56 | + sys.exit(1) |
| 57 | + |
| 58 | + # Read and bump chart version |
| 59 | + chart_content = chart_yaml.read_text() |
| 60 | + version_match = re.search(r'^version:\s*"?([^"\n]+)"?', chart_content, re.MULTILINE) |
| 61 | + if not version_match: |
| 62 | + print("Error: could not find version in Chart.yaml") |
| 63 | + sys.exit(1) |
| 64 | + |
| 65 | + current_chart_version = version_match.group(1) |
| 66 | + new_chart_version = bump_version(current_chart_version) |
| 67 | + |
| 68 | + chart_content = re.sub( |
| 69 | + r'^version:\s*.*$', |
| 70 | + f'version: "{new_chart_version}"', |
| 71 | + chart_content, |
| 72 | + flags=re.MULTILINE, |
| 73 | + ) |
| 74 | + chart_yaml.write_text(chart_content) |
| 75 | + print(f"Chart version: {current_chart_version} -> {new_chart_version}") |
| 76 | + |
| 77 | + # Update web image tag in values.yaml |
| 78 | + values_content = values_yaml.read_text() |
| 79 | + values_content = re.sub( |
| 80 | + r'(^ web:\s*\n tag:\s*).*$', |
| 81 | + rf'\g<1>{args.web_version}', |
| 82 | + values_content, |
| 83 | + flags=re.MULTILINE, |
| 84 | + ) |
| 85 | + values_yaml.write_text(values_content) |
| 86 | + print(f"Web image tag: {args.web_version}") |
| 87 | + |
| 88 | + |
| 89 | +if __name__ == "__main__": |
| 90 | + main() |
0 commit comments