Skip to content

Commit ccce7f6

Browse files
authored
Create bump.py
Signed-off-by: NxPKG <[email protected]>
1 parent ccfb677 commit ccce7f6

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

bump.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import os
2+
import sys
3+
import re
4+
5+
def read_version():
6+
with open('gpt_computer_agent/__init__.py', 'r') as file:
7+
for line in file:
8+
match = re.search(r"__version__ = '(.*)'", line)
9+
if match:
10+
return match.group(1)
11+
12+
def increment_version(part, version):
13+
major, minor, patch = map(int, version.split('.'))
14+
if part == 'major':
15+
major += 1
16+
minor = 0
17+
patch = 0
18+
elif part == 'minor':
19+
minor += 1
20+
patch = 0
21+
elif part == 'patch':
22+
patch += 1
23+
return f'{major}.{minor}.{patch}'
24+
25+
def write_version(version):
26+
with open('gpt_computer_agent/__init__.py', 'r+') as file:
27+
content = file.read()
28+
content = re.sub(r"__version__ = '.*'", f"__version__ = '{version}'", content)
29+
file.seek(0)
30+
file.write(content)
31+
32+
def update_version(version):
33+
files = ['setup.py']
34+
for file in files:
35+
with open(file, 'r+') as f:
36+
content = f.read()
37+
content = re.sub(r' version=".*"', f' version="{version}"', content)
38+
f.seek(0)
39+
f.write(content)
40+
41+
def create_tag(version):
42+
os.system(f"git tag v{version}")
43+
44+
def create_commit(version):
45+
os.system("git add .")
46+
os.system(f"git commit -m 'Changed version number with v{version}'")
47+
48+
49+
def push():
50+
os.system("git push")
51+
os.system("git push --tag")
52+
53+
def main():
54+
part = sys.argv[1]
55+
version = read_version()
56+
new_version = increment_version(part, version)
57+
write_version(new_version)
58+
update_version(new_version)
59+
create_commit(new_version)
60+
create_tag(new_version)
61+
push()
62+
63+
if __name__ == '__main__':
64+
main()

0 commit comments

Comments
 (0)