forked from Upsonic/gpt-computer-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump.py
65 lines (54 loc) · 1.64 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
import os
import sys
import re
def read_version():
with open('gpt_computer_assistant/__init__.py', 'r') as file:
for line in file:
match = re.search(r"__version__ = '(.*)'", line)
if match:
return match.group(1)
def increment_version(part, version):
major, minor, patch = map(int, version.split('.'))
if part == 'major':
major += 1
minor = 0
patch = 0
elif part == 'minor':
minor += 1
patch = 0
elif part == 'patch':
patch += 1
return f'{major}.{minor}.{patch}'
def write_version(version):
with open('gpt_computer_assistant/__init__.py', 'r+') as file:
content = file.read()
content = re.sub(r"__version__ = '.*'", f"__version__ = '{version}'", content)
file.seek(0)
file.write(content)
def update_version(version):
files = ['setup.py']
for file in files:
with open(file, 'r+') as f:
content = f.read()
content = re.sub(r' version=".*"', f' version="{version}"', content)
f.seek(0)
f.write(content)
def create_tag(version):
os.system(f"git tag v{version}")
def create_commit(version):
os.system("git add .")
os.system(f"git commit -m 'Changed version number with v{version}'")
def push():
os.system("git push")
os.system("git push --tag")
def main():
part = sys.argv[1]
version = read_version()
new_version = increment_version(part, version)
write_version(new_version)
update_version(new_version)
create_commit(new_version)
create_tag(new_version)
push()
if __name__ == '__main__':
main()