-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_version.py
More file actions
43 lines (34 loc) · 1.25 KB
/
Copy pathupdate_version.py
File metadata and controls
43 lines (34 loc) · 1.25 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
#!/usr/bin/env python3
"""
Update version.py with the current Git tag
Used by GitHub Actions during release builds
"""
import re
import sys
from datetime import datetime
def update_version(tag):
"""Update version.py with the provided tag"""
try:
# Remove 'v' prefix if present
clean_tag = tag.lstrip('v')
# Read current version.py
with open('version.py', 'r', encoding='utf-8') as f:
content = f.read()
# Update fallback version and build date (used for packaged builds)
content = re.sub(r'_FALLBACK_VERSION = "[^"]*"', f'_FALLBACK_VERSION = "{clean_tag}"', content)
content = re.sub(r'_FALLBACK_BUILD_DATE = "[^"]*"', f'_FALLBACK_BUILD_DATE = "{datetime.now().strftime("%Y-%m-%d")}"', content)
# Write back
with open('version.py', 'w', encoding='utf-8') as f:
f.write(content)
print(f'Successfully updated version to {clean_tag}')
return True
except Exception as e:
print(f'Error updating version: {e}')
return False
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Usage: python update_version.py <tag>')
sys.exit(1)
tag = sys.argv[1]
success = update_version(tag)
sys.exit(0 if success else 1)