-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_version.py
More file actions
executable file
·99 lines (75 loc) · 2.91 KB
/
update_version.py
File metadata and controls
executable file
·99 lines (75 loc) · 2.91 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
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
"""
Version update script for reforge-python SDK.
Updates both VERSION file and pyproject.toml to keep them in sync.
Usage:
python update_version.py 0.13.0
python update_version.py --current # Show current version
"""
import argparse
import re
import sys
from pathlib import Path
def get_current_version():
"""Get current version from VERSION file."""
version_file = Path(__file__).parent / "sdk_reforge" / "VERSION"
try:
return version_file.read_text().strip()
except FileNotFoundError:
return "unknown"
def update_version_file(new_version: str):
"""Update the VERSION file."""
version_file = Path(__file__).parent / "sdk_reforge" / "VERSION"
version_file.write_text(new_version + "\n")
print(f"✓ Updated {version_file}")
def update_pyproject_toml(new_version: str):
"""Update the version in pyproject.toml."""
toml_file = Path(__file__).parent / "pyproject.toml"
content = toml_file.read_text()
# Update version line
updated_content = re.sub(
r'^version = ".*"$', f'version = "{new_version}"', content, flags=re.MULTILINE
)
if content == updated_content:
print(f"⚠ No version found in {toml_file}")
return False
toml_file.write_text(updated_content)
print(f"✓ Updated {toml_file}")
return True
def validate_version(version: str) -> bool:
"""Validate version format (semantic versioning)."""
pattern = r"^\d+\.\d+\.\d+(-[a-zA-Z0-9\-\.]+)?$"
return bool(re.match(pattern, version))
def main():
parser = argparse.ArgumentParser(description="Update reforge-python SDK version")
parser.add_argument("version", nargs="?", help="New version number (e.g., 0.13.0)")
parser.add_argument("--current", action="store_true", help="Show current version")
args = parser.parse_args()
if args.current:
current = get_current_version()
print(f"Current version: {current}")
return
if not args.version:
print("Error: Version number required (or use --current)")
print("Usage: python update_version.py 0.13.0")
sys.exit(1)
new_version = args.version.strip()
if not validate_version(new_version):
print(f"Error: Invalid version format '{new_version}'")
print("Expected format: MAJOR.MINOR.PATCH (e.g., 0.13.0)")
sys.exit(1)
current = get_current_version()
print(f"Updating version: {current} → {new_version}")
try:
update_version_file(new_version)
update_pyproject_toml(new_version)
print(f"\n✅ Successfully updated to version {new_version}")
print("\nDon't forget to:")
print("1. Commit the changes")
print("2. Tag the release: git tag v" + new_version)
print("3. Push with tags: git push --tags")
except Exception as e:
print(f"\n❌ Error updating version: {e}")
sys.exit(1)
if __name__ == "__main__":
main()