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