From e4b166bca6a27be1c2d43c1ab27ceaf59658b4f8 Mon Sep 17 00:00:00 2001 From: Starfire-Win Date: Mon, 10 Jun 2024 15:46:03 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20up=20version=20py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/upversion.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/upversion.py b/.github/upversion.py index 3d66ea6..1cf8dfc 100644 --- a/.github/upversion.py +++ b/.github/upversion.py @@ -89,9 +89,22 @@ def read_current_branch() -> str: # 判断当前分支 return branch.replace("* ", "") -def read_current_version() -> str: +def read_local_username() -> str: + result = subprocess.run(['git', 'config', 'user.name'], stdout=subprocess.PIPE) + return result.stdout.decode('utf-8').strip() + + +def read_local_email() -> str: + result = subprocess.run(['git', 'config', 'user.email'], stdout=subprocess.PIPE) + return result.stdout.decode('utf-8').strip() + + +def read_current_version() -> str | None: subprocess.run(['git', 'fetch', '--tags'], check=True) tags = os.popen("git tag").read().split("\n") + # 需要判断是否有标签列表 + if len(tags) == 0: + return None # 所有标签去掉空字符串 -preview标签去掉preview 然后按照version排序 1.2.3-preview -> 1.3.0-preview tags = sorted([tag.replace("-preview", "") for tag in tags if tag], key=lambda x: list(map(int, x.split(".")))) return tags[-1] @@ -102,8 +115,8 @@ def read_current_version() -> str: current_path = os.getcwd() print("当前路径: " + current_path) -username = "Star fire" -email = "xinansky99@gmail.com" +username = read_local_username() +email = read_local_email() print("用户名称: " + username) print("用户邮箱: " + email) @@ -137,14 +150,18 @@ def read_current_version() -> str: step_function() version = read_current_version() # 读取当前版本号 -print("当前版本号: " + version) -# 递增版本号 -version_list = version.split(".") -if is_preview: - version_list[2] = str(int(version_list[2]) + 1) + "-preview" +if version is None: + version = "1.0.0" + new_version = "1.0.0" else: - version_list[2] = str(int(version_list[2]) + 1) -new_version = ".".join(version_list) + # 递增版本号 + version_list = version.split(".") + if is_preview: + version_list[2] = str(int(version_list[2]) + 1) + "-preview" + else: + version_list[2] = str(int(version_list[2]) + 1) + new_version = ".".join(version_list) +print("版本号: {0} -> {1}".format(version, new_version)) # 写入新版本号 with open("package.json", "r+") as f: