-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathbump_version.py
More file actions
60 lines (46 loc) · 1.7 KB
/
bump_version.py
File metadata and controls
60 lines (46 loc) · 1.7 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
# -*- coding: utf-8 -*-
"""
Script to update the semantic version in pyproject.toml and Dockerfile.
Called automatically from semantic-release hooks.
see: release.config.js in the root directory.
Usage:
python scripts/bump_version.py <new_version>
Updates:
- app/__version__.py
- pyproject.toml
- Dockerfile
"""
import re
import sys
from pathlib import Path
def update_version_in_file(filepath, pattern, replacement):
"""Update the version in the specified file."""
path = Path(filepath)
text = path.read_text(encoding="utf-8")
new_text = re.sub(pattern, replacement, text)
path.write_text(new_text, encoding="utf-8")
def main():
"""Main function to update version in multiple files."""
if len(sys.argv) != 2:
print("Usage: python bump_version.py <new_version>")
sys.exit(1)
new_version = sys.argv[1]
# Validate semantic version: ##.##.##
if not re.match(r"^\d+\.\d+\.\d+$", new_version):
print("Error: Version must be in format ##.##.## (e.g., 0.1.20)")
sys.exit(1)
# Update __version__.py
update_version_in_file("app/__version__.py", r'__version__\s*=\s*["\'].*?["\']', f'__version__ = "{new_version}"')
# Update pyproject.toml
update_version_in_file("pyproject.toml", r'version\s*=\s*["\'].*?["\']', f'version = "{new_version}"')
# Update Dockerfile (example: ARG VERSION=...)
update_version_in_file(
"Dockerfile",
r'org\.opencontainers\.image\.version="[^"]+"',
f'org.opencontainers.image.version="{new_version}"',
)
print(
f"Version updated to {new_version} in __version__.py, pyproject.toml, Dockerfile and helm/charts/smarter/Chart.yaml"
)
if __name__ == "__main__":
main()