From 7070dd88daadf7730a7902fd69fee1fcb21d34e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=AD=E9=B8=AD=E3=80=8C=E3=82=AB=E3=83=A2=E3=80=8D?= <89643991+DuckDuckStudio@users.noreply.github.com> Date: Fri, 3 Apr 2026 20:41:57 +0800 Subject: [PATCH 1/5] =?UTF-8?q?ci(release):=20=E8=87=AA=E5=8A=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yaml | 22 +++++++++ .scripts/update_version.py | 87 ++++++++++++++++++++++++++++++++++ Installer.iss | 2 +- PinAction/Program.cs | 2 +- 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 .scripts/update_version.py diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 36ffbb3..84f629d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,6 +2,11 @@ name: Release on: workflow_dispatch: + inputs: + version: + description: 版本号 (不带v) + required: true + default: 2.3.3 release: types: [published] @@ -23,6 +28,23 @@ jobs: with: dotnet-version: 10.x + - name: 配置 Python + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 + with: + python-version: 3.x + + - name: 更新版本号 + shell: bash + run: |- + if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then + version="${GITHUB_EVENT_INPUTS_VERSION#v}" + else + version="${GITHUB_REF_NAME#refs/tags/}" + version="${version#v}" + fi + + python ".scripts/update_version.py" "$version" + - name: 发布 run: dotnet publish PinAction --configuration Release diff --git a/.scripts/update_version.py b/.scripts/update_version.py new file mode 100644 index 0000000..3b33ab8 --- /dev/null +++ b/.scripts/update_version.py @@ -0,0 +1,87 @@ +""" +更新 PinAction/Program.cs 和 Installer.iss 中的版本号。 +""" + +import os.path +import sys + + +def update_ver(root: str, path: str, old: str, new: str, max_matches: int = 1): + """ + 更新文件中的版本号 + + Args: + root (str): 相对路径 path 基于的路径 + path (str): 文件基于 root 的相对路径 + old (str): 旧内容 + new (str): 新内容 + max_matches (int): 最大匹配行数。默认为 1 + """ + + if max_matches < 1: + raise ValueError("最大匹配次数 max_matches 不应小于 1") + + path = os.path.normpath(os.path.join(root, path)) + + matches: int = 0 + with open(path, "r", encoding="utf-8") as f: + lines: list[str] = f.readlines() + + for index, line in enumerate(lines): + if old in line.rstrip("\n"): + new_line: str = line.replace(old, new, 1) + lines[index] = new_line + matches += 1 + # pylint: disable=C0301:line-too-long + print(f"({matches}/{max_matches}) 匹配 {os.path.relpath(path, root)} 第 {index+1} 行: \"{lines[index].rstrip("\n")}\" -> \"{new_line.rstrip("\n")}\"") + + if matches == max_matches: + break + + with open(path, "w", encoding="utf-8") as f: + f.writelines(lines) + + +def main(args: list[str]) -> int: + """ + 入口函数 + + Args: + args (list[str]): 命令行参数 + + Returns: + int: 退出代码 + """ + + if len(args) != 1: + print("使用方法: update_version.py ") + return 1 + + version = args[0] + print(f"版本号: {version}") + + # os.path.dirname(__file__) -> .scripts/(update_version.py) + # os.path.dirname(os.path.dirname(__file__)) -> ./[.scripts/(update_version.py)] + root: str = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + # 更新版本号 + update_ver( + root, + "installer.iss", + "AppVersion=develop", + f"AppVersion={version}" + ) + update_ver( + root, + "PinAction/Program.cs", + # pylint: disable=C0301:line-too-long + # 不是 f-string 的不用转义 {} + 'AnsiConsole.MarkupLine($"PinAction {Strings.Version} [green]develop[/] by [link=https://duckduckstudio.github.io/yazicbs.github.io/]鸭鸭「カモ」[/]");', + f'AnsiConsole.MarkupLine($"PinAction {{Strings.Version}} [green]{version}[/] by [link=https://duckduckstudio.github.io/yazicbs.github.io/]鸭鸭「カモ」[/]");', + ) + + return 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/Installer.iss b/Installer.iss index 71cd48d..6ac2d4b 100644 --- a/Installer.iss +++ b/Installer.iss @@ -1,6 +1,6 @@ [Setup] AppName=PinAction -AppVersion=1.0.1 +AppVersion=develop DefaultDirName={pf}\DuckStudio\PinAction VersionInfoCopyright=版权所有 (c) 2026 鸭鸭「カモ」 LicenseFile=LICENSE.txt diff --git a/PinAction/Program.cs b/PinAction/Program.cs index 17d3b4b..ee2398c 100644 --- a/PinAction/Program.cs +++ b/PinAction/Program.cs @@ -48,7 +48,7 @@ static int Main(string[] args) case "--version": case "--ver": case "-v": - AnsiConsole.MarkupLine($"PinAction {Strings.Version} [green]1.0.1[/] by [link=https://duckduckstudio.github.io/yazicbs.github.io/]鸭鸭「カモ」[/]"); + AnsiConsole.MarkupLine($"PinAction {Strings.Version} [green]develop[/] by [link=https://duckduckstudio.github.io/yazicbs.github.io/]鸭鸭「カモ」[/]"); Console.WriteLine(); AnsiConsole.MarkupLine(Strings.HelpVer2License); return 0; From 8e79882cd729bec081b6599706d09bff3fae66d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=AD=E9=B8=AD=E3=80=8C=E3=82=AB=E3=83=A2=E3=80=8D?= <89643991+DuckDuckStudio@users.noreply.github.com> Date: Fri, 3 Apr 2026 21:03:15 +0800 Subject: [PATCH 2/5] ci(release): PYTHONIOENCODING: utf-8 --- .github/workflows/release.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 84f629d..1a63e90 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,6 +16,8 @@ permissions: jobs: release: runs-on: windows-latest + env: + PYTHONIOENCODING: utf-8 steps: - name: 检出代码 From d22b6052138d3e7dafe88f20c69c86e840228c44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=AD=E9=B8=AD=E3=80=8C=E3=82=AB=E3=83=A2=E3=80=8D?= <89643991+DuckDuckStudio@users.noreply.github.com> Date: Sat, 4 Apr 2026 08:32:01 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=9C=A8=E6=9B=B4=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=E5=89=8D=20.strip()=20=E5=B9=B6=20=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E7=89=88=E6=9C=AC=E5=8F=B7=E6=98=AF=E5=90=A6=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .scripts/update_version.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.scripts/update_version.py b/.scripts/update_version.py index 3b33ab8..ae8dcf7 100644 --- a/.scripts/update_version.py +++ b/.scripts/update_version.py @@ -57,7 +57,9 @@ def main(args: list[str]) -> int: print("使用方法: update_version.py ") return 1 - version = args[0] + version: str = args[0].strip() + if not version: + raise ValueError("版本号不能为空") print(f"版本号: {version}") # os.path.dirname(__file__) -> .scripts/(update_version.py) From 6f3c318592cabb33f263c2a3ffe227672f63b251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=AD=E9=B8=AD=E3=80=8C=E3=82=AB=E3=83=A2=E3=80=8D?= <89643991+DuckDuckStudio@users.noreply.github.com> Date: Sat, 4 Apr 2026 08:33:08 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=A1=A5=E5=85=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E6=AD=A5=E9=AA=A4=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=20env=20=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1a63e90..25f7fef 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -37,6 +37,8 @@ jobs: - name: 更新版本号 shell: bash + env: + GITHUB_EVENT_INPUTS_VERSION: ${{ github.event.inputs.version }} run: |- if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then version="${GITHUB_EVENT_INPUTS_VERSION#v}" From c78f71b3d50220adfb4d957cd43c43b3e06a3494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=AD=E9=B8=AD=E3=80=8C=E3=82=AB=E3=83=A2=E3=80=8D?= <89643991+DuckDuckStudio@users.noreply.github.com> Date: Sat, 4 Apr 2026 08:53:21 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .scripts/update_version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.scripts/update_version.py b/.scripts/update_version.py index ae8dcf7..985eb2f 100644 --- a/.scripts/update_version.py +++ b/.scripts/update_version.py @@ -29,11 +29,11 @@ def update_ver(root: str, path: str, old: str, new: str, max_matches: int = 1): for index, line in enumerate(lines): if old in line.rstrip("\n"): - new_line: str = line.replace(old, new, 1) - lines[index] = new_line matches += 1 + new_line: str = line.replace(old, new, 1) # pylint: disable=C0301:line-too-long print(f"({matches}/{max_matches}) 匹配 {os.path.relpath(path, root)} 第 {index+1} 行: \"{lines[index].rstrip("\n")}\" -> \"{new_line.rstrip("\n")}\"") + lines[index] = new_line if matches == max_matches: break