Skip to content

Commit a3fdf07

Browse files
committed
feat: add automated version bumping script for project metadata files
1 parent 5e44d5c commit a3fdf07

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

scripts/bump_version.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import os
4+
import re
5+
6+
def bump_file(filepath, pattern, replacement):
7+
if not os.path.exists(filepath):
8+
print(f"[!] error: {filepath} not found.")
9+
return False
10+
11+
with open(filepath, 'r', encoding='utf-8') as f:
12+
content = f.read()
13+
14+
# count=1 ensures we only replace the first occurrence
15+
# especially important for Cargo.toml where dependencies might have versions
16+
new_content = re.sub(pattern, replacement, content, count=1)
17+
18+
if content != new_content:
19+
with open(filepath, 'w', encoding='utf-8') as f:
20+
f.write(new_content)
21+
print(f"[v] updated {os.path.basename(filepath)}")
22+
return True
23+
else:
24+
print(f"[-] skipped {os.path.basename(filepath)} (no match or already set)")
25+
return False
26+
27+
def main():
28+
if len(sys.argv) != 2:
29+
print("usage: ./bump_version.py <new_version>")
30+
print("example: ./bump_version.py 1.3.0")
31+
sys.exit(1)
32+
33+
new_version = sys.argv[1].strip()
34+
35+
# remove 'v' prefix if present
36+
if new_version.startswith('v'):
37+
new_version = new_version[1:]
38+
39+
# basic semver check
40+
if not re.match(r'^\d+\.\d+\.\d+$', new_version):
41+
print("[!] error: version must be in format x.y.z (e.g., 1.3.0)")
42+
sys.exit(1)
43+
44+
print(f"[*] bumping version to {new_version}...\n")
45+
46+
tasks = [
47+
(
48+
"CMakeLists.txt",
49+
r'project\(simd-fp VERSION \d+\.\d+\.\d+ LANGUAGES C CXX\)',
50+
f'project(simd-fp VERSION {new_version} LANGUAGES C CXX)'
51+
),
52+
(
53+
"js/package.json",
54+
r'"version": "\d+\.\d+\.\d+"',
55+
f'"version": "{new_version}"'
56+
),
57+
(
58+
"pyproject.toml",
59+
r'version = "\d+\.\d+\.\d+"',
60+
f'version = "{new_version}"'
61+
),
62+
(
63+
"setup.py",
64+
r"version='\d+\.\d+\.\d+'",
65+
f"version='{new_version}'"
66+
),
67+
(
68+
"rust/Cargo.toml",
69+
r'version = "\d+\.\d+\.\d+"',
70+
f'version = "{new_version}"'
71+
)
72+
]
73+
74+
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
75+
76+
all_success = True
77+
for rel_path, pattern, replacement in tasks:
78+
filepath = os.path.join(root_dir, rel_path)
79+
success = bump_file(filepath, pattern, replacement)
80+
if not success:
81+
all_success = False
82+
83+
print("\n[v] done.")
84+
if not all_success:
85+
print("[!] some files were not updated. check warnings above.")
86+
87+
if __name__ == '__main__':
88+
main()

0 commit comments

Comments
 (0)