-
Notifications
You must be signed in to change notification settings - Fork 51
/
bump.py
79 lines (64 loc) · 2.32 KB
/
bump.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
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
import argparse
parser = argparse.ArgumentParser(description="Bump version")
parser.add_argument("--build", type=int, help="build number")
parser.add_argument("--sem", type=str, help="Semantic version part")
parser.add_argument("--minor", type=bool, help="Minor")
parser.add_argument("--bug", type=bool, help="Bug")
def run(args):
with open("VERSION", "r") as f:
version = f.read().strip()
major, minor, bug = version.split(".")
major = int(major)
minor = int(minor)
bug = int(bug)
version_post = ""
if args.build:
version_post = f"-post{args.build}"
elif args.sem == "major":
major += 1
minor = 0
bug = 0
elif args.sem == "minor":
minor += 1
bug = 0
elif args.sem == "bug":
bug += 1
version = f"{major}.{minor}.{bug}{version_post}"
# rust does not like `.` in post but python requires is
python_version = version.replace("-", ".")
with open("VERSION", "w") as f:
f.write(python_version)
if args.sem:
# we only set other versions if we are not bumping a sem version
return
# replace node binding toml version as well
with open("nucliadb_node_binding/Cargo.toml", "r") as f:
cargo = f.read()
new_cargo = []
for line in cargo.splitlines():
if line.startswith("version ="):
line = f'version = "{version}"'
new_cargo.append(line)
with open("nucliadb_node_binding/Cargo.toml", "w") as f:
f.write("\n".join(new_cargo))
# go through each requirements.txt and update the version to the new bump
for req_filepath in (
"nucliadb/requirements.txt",
"nucliadb_utils/requirements.txt",
"nucliadb_sdk/requirements.txt",
"nucliadb_models/requirements.txt",
"nucliadb_dataset/requirements.txt",
):
with open(req_filepath, "r") as f:
req_lines = []
for line in f.read().splitlines():
if line.startswith("nucliadb-") and (
"=" not in line and ">" not in line and "~" not in line
):
line = f"{line}>={python_version}"
req_lines.append(line)
with open(req_filepath, "w") as f:
f.write("\n".join(req_lines))
if __name__ == "__main__":
args = parser.parse_args()
run(args)