-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbump_major.py
More file actions
30 lines (25 loc) · 993 Bytes
/
bump_major.py
File metadata and controls
30 lines (25 loc) · 993 Bytes
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
import fileinput
import os
version_file = os.getenv("VERSION_FILE")
if not os.path.isfile(version_file):
raise ValueError(f"environment variable `VERSION_FILE` is not a file: {version_file}")
version_var_name = "VERSION_MAJOR"
minor_var_name = "VERSION_MINOR"
build_var_name = "VERSION_BUILD"
alpha_var_name = "VERSION_ALPHA"
with open(version_file, "r", encoding="utf-8") as v:
for line in v.readlines():
if line.startswith(version_var_name):
version = int(line.split("=")[-1])
new_version = int(version) + 1
for line in fileinput.input(version_file, inplace=True):
if line.startswith(version_var_name):
print(f"{version_var_name} = {new_version}")
elif line.startswith(minor_var_name):
print(f"{minor_var_name} = 0")
elif line.startswith(build_var_name):
print(f"{build_var_name} = 0")
elif line.startswith(alpha_var_name):
print(f"{alpha_var_name} = 0")
else:
print(line.rstrip('\n'))