-
Notifications
You must be signed in to change notification settings - Fork 1
/
bump_version.py
54 lines (41 loc) · 1.54 KB
/
bump_version.py
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
import re
import sys
def read_version(filename):
with open(filename, "r") as f:
content = f.read()
match = re.search(r'version\s*=\s*"(\d+\.\d+\.\d+)"', content)
if match:
return match.group(1)
else:
raise ValueError(f"Version not found in {filename}")
def write_version(filename, version):
with open(filename, "r") as f:
content = f.read()
with open(filename, "w") as f:
content = re.sub(r'version\s*=\s*"\d+\.\d+\.\d+"', f'version="{version}"', content)
f.write(content)
def bump_version(version, bump_type):
version_parts = version.split(".")
if bump_type == "major":
version_parts[0] = str(int(version_parts[0]) + 1)
version_parts[1] = "0"
version_parts[2] = "0"
elif bump_type == "minor":
version_parts[1] = str(int(version_parts[1]) + 1)
version_parts[2] = "0"
elif bump_type == "patch":
version_parts[2] = str(int(version_parts[2]) + 1)
else:
raise ValueError("Invalid bump type. Use 'major', 'minor', or 'patch'")
return ".".join(version_parts)
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: python bump_version.py <bump_type> <file1> <file2> ...")
sys.exit(1)
bump_type = sys.argv[1]
files = sys.argv[2:]
for filename in files:
version = read_version(filename)
new_version = bump_version(version, bump_type)
write_version(filename, new_version)
print(f"Version bumped {bump_type}: {version} -> {new_version}")