Skip to content

Commit 88941d3

Browse files
committed
Add release.py
1 parent b2917b0 commit 88941d3

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

release.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import subprocess
3+
import re
4+
5+
def get_latest_tag():
6+
output = subprocess.check_output(['git', 'tag'])
7+
tags = output.decode('utf-8').split('\n')[:-1]
8+
latest_tag = sorted(tags, key=lambda t: tuple(map(int, re.match(r'v(\d+)\.(\d+)\.(\d+)', t).groups())))[-1]
9+
return latest_tag
10+
11+
def update_version_number(latest_tag, increment):
12+
major, minor, patch = map(int, re.match(r'v(\d+)\.(\d+)\.(\d+)', latest_tag).groups())
13+
if increment == 'X':
14+
major += 1
15+
minor, patch = 0, 0
16+
elif increment == 'Y':
17+
minor += 1
18+
patch = 0
19+
elif increment == 'Z':
20+
patch += 1
21+
new_version = f"v{major}.{minor}.{patch}"
22+
return new_version
23+
24+
def main():
25+
print("当前最近的Git标签:")
26+
latest_tag = get_latest_tag()
27+
print(latest_tag)
28+
29+
print("请选择要递增的版本号部分(X, Y, Z):")
30+
increment = input().upper()
31+
32+
while increment not in ['X', 'Y', 'Z']:
33+
print("输入错误,请输入X, Y或Z:")
34+
increment = input().upper()
35+
36+
new_version = update_version_number(latest_tag, increment)
37+
print(f"新的版本号为:{new_version}")
38+
39+
print("确认更新版本号并推送到远程仓库?(y/n)")
40+
confirmation = input().lower()
41+
42+
if confirmation == 'y':
43+
subprocess.run(['git', 'tag', new_version])
44+
subprocess.run(['git', 'push', 'origin', new_version])
45+
print("新版本号已创建并推送到远程仓库。")
46+
else:
47+
print("操作已取消。")
48+
49+
if __name__ == '__main__':
50+
main()

0 commit comments

Comments
 (0)