-
Notifications
You must be signed in to change notification settings - Fork 0
/
bumpversion.py
82 lines (53 loc) · 1.84 KB
/
bumpversion.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
80
81
82
import sys
import requests
def throw_error(text):
print("❌ ERROR: " + text)
sys.exit(1)
def throw_warning(text):
print("⚠️ WARNING: " + text)
def get_version():
respone = requests.get(
"https://api.github.com/repos/robotcoral/coral-app/releases/latest"
).json()
return respone["tag_name"]
def new_version_greater(new_ver, old_ver):
new_ver = list(map(int, new_ver.split(".")))
old_ver = list(map(int, old_ver.split(".")))
for i in range(0, 3):
if new_ver[i] > old_ver[i]:
return True
return False
def bump_documentation(version):
print("\n> Loading conf.py")
with open("./source/conf.py", "r") as f:
file = f.read()
begin_version_line = file.find('release = "')
begin_version = begin_version_line + len('release = "')
end_version = file.find('"', begin_version)
env_com_version = file[begin_version:end_version]
print("Old Version: " + env_com_version)
print("New Version: " + version)
check_version = new_version_greater(version, env_com_version)
if not (check_version):
throw_warning("New version is <= old version")
print("✅ SUCCESS - no changes")
return
print("> Writing to conf.py")
with open("./source/conf.py", "w") as f:
f.write(file[0:begin_version] + version + file[end_version:])
print("✅ SUCCESS")
def export_version(version):
with open("./doc_version.txt", "w") as f:
f.write(version)
def bump_version(version):
bump_documentation(version)
if __name__ == "__main__":
print("### Robot Coral CI ###\n")
print("---Loading new version number---")
version = get_version()
print("\n---Bumping versions---")
print("New version: " + version)
bump_version(version)
export_version(version)
print("\n----------")
print("\n✅ SUCCESS")