Skip to content

Commit 31186bc

Browse files
committed
✨ up version
1 parent 442b212 commit 31186bc

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

.github/upversion.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
def get_latest_github_tag(repo_url) -> str:
1111
# 从仓库 URL 提取用户和仓库名称
1212
repo_path = repo_url.split("https://github.com/")[1].replace(".git", "")
13+
print(f"Fetching tags from {repo_path}")
1314
api_url = f"https://api.github.com/repos/{repo_path}/tags"
1415

15-
response = requests.get(api_url)
16+
response = requests.get(api_url, timeout=10)
1617

1718
if response.status_code == 200:
1819
tags = response.json()
@@ -80,9 +81,8 @@ def delete_folder(folder_path) -> None:
8081
print(exp)
8182

8283

83-
def read_current_branch() -> str:
84+
def read_current_branch() -> str: # 判断当前分支
8485
branches = os.popen("git branch").read().split("\n")
85-
# 判断当前分支
8686
for branch in branches:
8787
if branch.startswith("*"):
8888
return branch.replace("* ", "")
@@ -91,14 +91,13 @@ def read_current_branch() -> str:
9191
def read_current_version() -> str:
9292
subprocess.run(['git', 'fetch', '--tags'], check=True)
9393
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("."))))
9696
return tags[-1]
9797

9898

9999
# 切换上一级目录
100100
os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
101-
# subprocess.run(['cd', '..'], check=True, shell=True)
102101
current_path = os.getcwd()
103102
print("当前路径: " + current_path)
104103

@@ -137,6 +136,7 @@ def read_current_version() -> str:
137136
step_function()
138137

139138
version = read_current_version() # 读取当前版本号
139+
print("当前版本号: " + version)
140140
# 递增版本号
141141
version_list = version.split(".")
142142
if is_preview:
@@ -149,12 +149,12 @@ def read_current_version() -> str:
149149
with open("package.json", "r+") as f:
150150
package = json.load(f)
151151
current_version = package["version"]
152-
package["relatedPackages"]["com.aio.package"] = get_latest_github_tag('https://github.com/AIO-GAME/Common.git')
153152
package["version"] = new_version
153+
package["relatedPackages"]["com.aio.package"] = get_latest_github_tag('https://github.com/AIO-GAME/Common.git')
154154
f.seek(0)
155155
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"]))
158158
f.close()
159159

160160
# 上传到远程仓库 捕获异常
@@ -164,9 +164,9 @@ def read_current_version() -> str:
164164
subprocess.run(['git', 'add', 'package.json'], check=True)
165165
subprocess.run(['git', 'commit', '-m', f"✨ up version {current_branch} -> {new_version}"], check=True)
166166
subprocess.run(['git', 'push', 'origin', current_branch], check=True)
167-
print("上传到远程仓库({0})成功".format(current_branch))
167+
print("推送仓库: ({0})成功".format(current_branch))
168168
except Exception as e:
169-
print("上传到远程仓库({0})失败".format(current_branch))
169+
print("推送仓库: ({0})失败".format(current_branch))
170170
print(e)
171171

172172
steps = [

0 commit comments

Comments
 (0)