10
10
def get_latest_github_tag (repo_url ) -> str :
11
11
# 从仓库 URL 提取用户和仓库名称
12
12
repo_path = repo_url .split ("https://github.com/" )[1 ].replace (".git" , "" )
13
+ print (f"Fetching tags from { repo_path } " )
13
14
api_url = f"https://api.github.com/repos/{ repo_path } /tags"
14
15
15
- response = requests .get (api_url )
16
+ response = requests .get (api_url , timeout = 10 )
16
17
17
18
if response .status_code == 200 :
18
19
tags = response .json ()
@@ -80,9 +81,8 @@ def delete_folder(folder_path) -> None:
80
81
print (exp )
81
82
82
83
83
- def read_current_branch () -> str :
84
+ def read_current_branch () -> str : # 判断当前分支
84
85
branches = os .popen ("git branch" ).read ().split ("\n " )
85
- # 判断当前分支
86
86
for branch in branches :
87
87
if branch .startswith ("*" ):
88
88
return branch .replace ("* " , "" )
@@ -91,14 +91,13 @@ def read_current_branch() -> str:
91
91
def read_current_version () -> str :
92
92
subprocess .run (['git' , 'fetch' , '--tags' ], check = True )
93
93
tags = os .popen ("git tag" ).read ().split ("\n " )
94
- # 所有标签去掉空字符串 -preview标签去掉preview 然后按照version排序
95
- tags = sorted ([tag .replace ("-preview" , "" ) for tag in tags if tag ], key = lambda x : tuple (map (int , x .split ("." ))))
94
+ # 所有标签去掉空字符串 -preview标签去掉preview 然后按照version排序 1.2.3-preview -> 1.3.0-preview
95
+ tags = sorted ([tag .replace ("-preview" , "" ) for tag in tags if tag ], key = lambda x : list (map (int , x .split ("." ))))
96
96
return tags [- 1 ]
97
97
98
98
99
99
# 切换上一级目录
100
100
os .chdir (os .path .dirname (os .path .dirname (os .path .realpath (__file__ ))))
101
- # subprocess.run(['cd', '..'], check=True, shell=True)
102
101
current_path = os .getcwd ()
103
102
print ("当前路径: " + current_path )
104
103
@@ -137,6 +136,7 @@ def read_current_version() -> str:
137
136
step_function ()
138
137
139
138
version = read_current_version () # 读取当前版本号
139
+ print ("当前版本号: " + version )
140
140
# 递增版本号
141
141
version_list = version .split ("." )
142
142
if is_preview :
@@ -149,12 +149,12 @@ def read_current_version() -> str:
149
149
with open ("package.json" , "r+" ) as f :
150
150
package = json .load (f )
151
151
current_version = package ["version" ]
152
- package ["relatedPackages" ]["com.aio.package" ] = get_latest_github_tag ('https://github.com/AIO-GAME/Common.git' )
153
152
package ["version" ] = new_version
153
+ package ["relatedPackages" ]["com.aio.package" ] = get_latest_github_tag ('https://github.com/AIO-GAME/Common.git' )
154
154
f .seek (0 )
155
155
json .dump (package , f , indent = 2 )
156
- print ("写入新版本号成功: {0} -> {1}" .format (current_version , new_version ))
157
- print ("写入依赖版本号成功: {0}" .format (package ["relatedPackages" ]["com.aio.package" ]))
156
+ print ("写入配置: 版本号 {0} -> {1}" .format (current_version , new_version ))
157
+ print ("写入配置: 依赖库 {0} -> {1} " .format ("com.aio.package" , package ["relatedPackages" ]["com.aio.package" ]))
158
158
f .close ()
159
159
160
160
# 上传到远程仓库 捕获异常
@@ -164,9 +164,9 @@ def read_current_version() -> str:
164
164
subprocess .run (['git' , 'add' , 'package.json' ], check = True )
165
165
subprocess .run (['git' , 'commit' , '-m' , f"✨ up version { current_branch } -> { new_version } " ], check = True )
166
166
subprocess .run (['git' , 'push' , 'origin' , current_branch ], check = True )
167
- print ("上传到远程仓库 ({0})成功" .format (current_branch ))
167
+ print ("推送仓库: ({0})成功" .format (current_branch ))
168
168
except Exception as e :
169
- print ("上传到远程仓库 ({0})失败" .format (current_branch ))
169
+ print ("推送仓库: ({0})失败" .format (current_branch ))
170
170
print (e )
171
171
172
172
steps = [
0 commit comments