diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 536f51c..bf0ed63 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,92 +11,110 @@ jobs: build: runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest, windows-latest] + arch: [x86, x64, arm, arm64, amd64] steps: - name: 检出代码 + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} uses: actions/checkout@v4 - name: 设置 .NET 8.0.x + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} uses: actions/setup-dotnet@v4 with: dotnet-version: '8.0.x' - name: 设置 Python 3.x + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} uses: actions/setup-python@v5 with: python-version: '3.x' - name: 更新版本号 + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} + env: + PYTHONIOENCODING: utf-8 run: | - python "auto-scripts/Change-Version.py" "${{ github.event.inputs.version }}" + python "自动化脚本/修改版本号.py" "${{ github.event.inputs.version }}" - - name: 还原依赖 - run: dotnet restore ghv/ghv.csproj + - name: 更新架构信息 + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} + env: + PYTHONIOENCODING: utf-8 + run: | + python "自动化脚本/修改架构.py" "${{ matrix.arch }}" - - name: 构建 - run: dotnet build ghv/ghv.csproj --configuration Release --no-restore + - name: 发布 - Windows - x64/x86/arm64/amd64 + if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }} + run: | + dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r win-${{ matrix.arch }} + dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r win-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true - - name: 发布 - run: dotnet publish ghv/ghv.csproj --configuration Release --no-build --output ./output + - name: 发布 - linux - x64/arm/arm64/amd64 + if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }} + run: | + dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r linux-${{ matrix.arch }} + dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r linux-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true - name: 创建发行文件 - Windows - if: runner.os == 'Windows' + if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }} + shell: pwsh run: | # 创建Release目录 mkdir -p Release # 使用7z压缩为zip格式 - 7z a -tzip Release/GitHubView-${{ github.event.inputs.version }}-windows.zip output/* + 7z a -tzip Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.zip output/* # 创建安装包 curl -o "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl" "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl" iscc installer/Windows.iss - move installer/GitHubView-installer.exe Release/GitHubView-${{ github.event.inputs.version }}-Setup-windows.exe + iscc installer/SingleFile/Windows.iss + move installer/GitHubView-installer.exe Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-Setup.exe + move installer/SingleFile/GitHubView-installer.exe Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-Setup-SingleFile.exe + + # 单独处理单文件 + move output_SingleFile/ghv.exe Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile.exe - name: 创建发行文件 - Linux - if: runner.os == 'Linux' - env: - MAINTAINER_EMAIL: ${{ secrets.Maintainer_Email }} + if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }} + shell: bash run: | # 创建Release目录 - mkdir -p Release + mkdir -pv Release + + echo "构建tar包..." # 使用tar压缩 - tar -czvf Release/GitHubView-${{ github.event.inputs.version }}-linux.tar.gz -C output . - - # 安装 dpkg - sudo apt-get update - sudo apt-get install -y dpkg - # 创建 DEBIAN 目录和控制文件 - mkdir -p output/DEBIAN - echo 'Package: GitHubView' > output/DEBIAN/control - echo 'Version: ${{ github.event.inputs.version }}' >> output/DEBIAN/control - echo 'Section: base' >> output/DEBIAN/control - echo 'Priority: optional' >> output/DEBIAN/control - echo 'Architecture: all' >> output/DEBIAN/control - echo "Maintainer: 鸭鸭「カモ」 <${MAINTAINER_EMAIL}>" >> output/DEBIAN/control - echo 'Description: GHV Application' >> output/DEBIAN/control - # 生成安装包 - dpkg --build output ghv.deb - mv ghv.deb Release/GitHubView-${{ github.event.inputs.version }}-linux.deb + tar -czvf Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz -C output . - - name: 创建发行文件 - macOS - if: runner.os == 'macOS' - run: | - # 创建Release目录 - mkdir -p Release + # ======================================================= + echo "构建DEB包..." + mkdir -pv output_SingleFile/usr/local/bin/ + cp -pv output_SingleFile/ghv output_SingleFile/usr/local/bin/ - # 使用tar压缩 - tar -czvf Release/GitHubView-${{ github.event.inputs.version }}-macos.tar.gz -C output . + # 复制 DEBIAN 控制文件 + cp -rpv installer/SingleFile/DEBIAN output_SingleFile - # 创建安装包 - pkgbuild --root ./output --identifier DuckStudio.GitHubView --version ${{ github.event.inputs.version }} --install-location /Applications --scripts ./output GitHubView.pkg - mv GitHubView.pkg Release/GitHubView-${{ github.event.inputs.version }}-macos.pkg + # 生成安装包 + dpkg --build output_SingleFile ghv.deb + mv -v ghv.deb Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.deb + + # 验证安装包 + dpkg --info Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.deb + dpkg --contents Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.deb + + # ======================================================= + echo "发布单文件..." + # 单独处理单文件 + mv -v output_SingleFile/ghv Release/GitHubView-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile - name: 上传发行文件 + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} uses: actions/upload-artifact@v4 with: - name: ghv-${{ matrix.os }} + name: ghv-${{ github.event.inputs.version }}-${{ matrix.os }}-${{ matrix.arch }} path: ./Release diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 4ba1f48..ea0fb49 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -9,109 +9,119 @@ on: workflow_dispatch: jobs: - build: + build-nightly: runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest, windows-latest] + arch: [x86, x64, arm, arm64, amd64] steps: - name: 检出代码 + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} uses: actions/checkout@v4 - name: 设置 .NET 8.0.x + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} uses: actions/setup-dotnet@v4 with: dotnet-version: '8.0.x' - name: 设置 Python 3.x + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} uses: actions/setup-python@v5 with: python-version: '3.x' - - name: 生成版本号 - Unix - if: runner.os == 'Linux' || runner.os == 'macOS' + - name: 生成版本号 + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} + shell: bash run: | echo "NIGHTLY_VERSION=$(date +'%Y.%m.%d').${{ github.run_id }}" >> $GITHUB_ENV - echo "Generated version: $NIGHTLY_VERSION" - - - name: 生成版本号 - Windows - if: runner.os == 'Windows' - run: | - $date = Get-Date -Format "yyyy.MM.dd" - $version = "$date.${{ github.run_id }}" - echo "NIGHTLY_VERSION=$version" >> $env:GITHUB_ENV - echo "Generated version: ${{ env.NIGHTLY_VERSION }}" - name: 更新版本号 + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} + env: + PYTHONIOENCODING: utf-8 run: | - python "auto-scripts/Change-Version.py" "${{ env.NIGHTLY_VERSION }}" + python "自动化脚本/修改版本号.py" "${{ env.NIGHTLY_VERSION }}" - - name: 还原依赖 - run: dotnet restore ghv/ghv.csproj + - name: 更新架构信息 + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} + env: + PYTHONIOENCODING: utf-8 + run: | + python "自动化脚本/修改架构.py" "${{ matrix.arch }}" - - name: 构建 - run: dotnet build ghv/ghv.csproj --configuration Release --no-restore + - name: 发布 - Windows - x64/x86/arm64/amd64 + if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }} + run: | + dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r win-${{ matrix.arch }} + dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r win-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true - - name: 发布 - run: dotnet publish ghv/ghv.csproj --configuration Release --no-build --output ./output + - name: 发布 - linux - x64/arm/arm64/amd64 + if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }} + run: | + dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r linux-${{ matrix.arch }} + dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r linux-${{ matrix.arch }} /p:PublishSingleFile=true /p:PublishTrimmed=true - name: 创建发行文件 - Windows - if: runner.os == 'Windows' + if: ${{ runner.os == 'Windows' && matrix.arch != 'arm' }} + shell: pwsh run: | # 创建Release目录 mkdir -p Release # 使用7z压缩为zip格式 - 7z a -tzip Release/GitHubView-${{ env.NIGHTLY_VERSION }}-windows.zip output/* + 7z a -tzip Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.zip output/* # 创建安装包 curl -o "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl" "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl" iscc installer/Windows.iss - move installer/GitHubView-installer.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-Setup-windows.exe + iscc installer/SingleFile/Windows.iss + move installer/GitHubView-installer.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-Setup.exe + move installer/SingleFile/GitHubView-installer.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-Setup-SingleFile.exe + + # 单独处理单文件 + move output_SingleFile/ghv.exe Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile.exe - name: 创建发行文件 - Linux - if: runner.os == 'Linux' - env: - MAINTAINER_EMAIL: ${{ secrets.Maintainer_Email }} + if: ${{ runner.os == 'Linux' && matrix.arch != 'x86' }} + shell: bash run: | # 创建Release目录 - mkdir -p Release + mkdir -pv Release + + echo "构建tar包..." # 使用tar压缩 - tar -czvf Release/GitHubView-${{ env.NIGHTLY_VERSION }}-linux.tar.gz -C output . - - # 安装 dpkg - sudo apt-get update - sudo apt-get install -y dpkg - # 创建 DEBIAN 目录和控制文件 - mkdir -p output/DEBIAN - echo 'Package: GitHubView' > output/DEBIAN/control - echo 'Version: ${{ env.NIGHTLY_VERSION }}' >> output/DEBIAN/control - echo 'Section: base' >> output/DEBIAN/control - echo 'Priority: optional' >> output/DEBIAN/control - echo 'Architecture: all' >> output/DEBIAN/control - echo "Maintainer: 鸭鸭「カモ」 <${MAINTAINER_EMAIL}>" >> output/DEBIAN/control - echo 'Description: GHV Application' >> output/DEBIAN/control - # 生成安装包 - dpkg --build output ghv.deb - mv ghv.deb Release/GitHubView-${{ env.NIGHTLY_VERSION }}-linux.deb + tar -czvf Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz -C output . - - name: 创建发行文件 - macOS - if: runner.os == 'macOS' - run: | - # 创建Release目录 - mkdir -p Release + # ======================================================= + echo "构建DEB包..." + mkdir -pv output_SingleFile/usr/local/bin/ + cp -pv output_SingleFile/ghv output_SingleFile/usr/local/bin/ - # 使用tar压缩 - tar -czvf Release/GitHubView-${{ env.NIGHTLY_VERSION }}-macos.tar.gz -C output . + # 复制 DEBIAN 控制文件 + cp -rpv installer/SingleFile/DEBIAN output_SingleFile - # 创建安装包 - pkgbuild --root ./output --identifier DuckStudio.GitHubView --version ${{ env.NIGHTLY_VERSION }} --install-location /Applications --scripts ./output GitHubView.pkg - mv GitHubView.pkg Release/GitHubView-${{ env.NIGHTLY_VERSION }}-macos.pkg + # 生成安装包 + dpkg --build output_SingleFile ghv.deb + mv -v ghv.deb Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.deb + + # 验证安装包 + dpkg --info Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.deb + dpkg --contents Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}.deb + + # ======================================================= + echo "发布单文件..." + # 单独处理单文件 + mv -v output_SingleFile/ghv Release/GitHubView-${{ env.NIGHTLY_VERSION }}-${{ matrix.os }}-${{ matrix.arch }}-SingleFile - name: 发布 Nightly 版本 uses: softprops/action-gh-release@v2 + if: ${{ !((runner.os == 'Linux' && matrix.arch == 'x86') || (runner.os == 'Windows' && matrix.arch == 'arm')) }} with: name: GitHubView Nightly Release (${{ env.NIGHTLY_VERSION }}) tag_name: ${{ env.NIGHTLY_VERSION }} diff --git a/.gitignore b/.gitignore index 53bdee8..aaa4d85 100644 --- a/.gitignore +++ b/.gitignore @@ -365,3 +365,7 @@ FodyWeavers.xsd # Debug Config launchSettings.json .editorconfig + +# TEST +test.yml +test.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 63bb832..4466abe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,6 +44,15 @@ dotnet run --project ghv <命令或参数> ``` +### 构建发布 +> 只是 .NET 把这个步骤叫做发布,不是 LICENSE 的例外。 + +```bash +dotnet publish ghv/ghv.csproj --configuration Release --output ./output -r 系统-架构 +dotnet publish ghv/ghv.csproj --configuration Release --output ./output_SingleFile -r 系统-架构 /p:PublishSingleFile=true /p:PublishTrimmed=true # 单文件 +# 有关架构信息,请查看: https://aka.ms/netsdk1083 +``` + ## 报告问题 如果您发现了一个问题,请通过 GitHub Issues 报告。请提供尽可能详细的信息,以帮助我们重现和解决问题。 diff --git a/auto-scripts/Change-Version.py b/auto-scripts/Change-Version.py deleted file mode 100644 index b40f57a..0000000 --- a/auto-scripts/Change-Version.py +++ /dev/null @@ -1,45 +0,0 @@ -import os -import sys - -if len(sys.argv) != 2: - print("[ERROR] Usage: python Change-Version.py ") - sys.exit(1) - -new_version = sys.argv[1] -if not new_version: - print("[ERROR] Version cannot be empty") - sys.exit(1) -print(f"[INFO] New version: {new_version}") - -program = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))), "ghv", "Program.cs") -try: - # 读取文件内容 - with open(program, 'r', encoding='utf-8') as f: - content = f.read() - - # 替换文本 - content = content.replace('Version = "develop"', f'Version = "{new_version}"') - - # 写回文件 - with open(program, 'w', encoding='utf-8') as f: - f.write(content) -except Exception as e: - print(f"[ERROR] A error occurred when processing {program}: {e}") - sys.exit(1) - -iss_file = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))), "installer", "Windows.iss") -try: - # 读取文件内容 - with open(iss_file, 'r', encoding='utf-8') as f: - content = f.read() - - # 替换文本 - content = content.replace('AppVersion=develop', f'AppVersion={new_version}') - - # 写回文件 - with open(iss_file, 'w', encoding='utf-8') as f: - f.write(content) -except Exception as e: - print(f"[ERROR] A error occurred when processing {iss_file}: {e}") - sys.exit(1) - diff --git a/installer/SingleFile/DEBIAN/control b/installer/SingleFile/DEBIAN/control new file mode 100644 index 0000000..2bff6bd --- /dev/null +++ b/installer/SingleFile/DEBIAN/control @@ -0,0 +1,10 @@ +Package: GitHubView +Version: develop +Section: utils +Priority: optional +Architecture: 这是一个架构 +Maintainer: Duck Studio +Description: Viewing content on GitHub in your console. +Homepage: https://github.com/DuckDuckStudio/GitHubView +License: GNU General Public License v3.0 +Changes: https://github.com/DuckDuckStudio/GitHubView/releases/tag/develop diff --git a/installer/SingleFile/Windows.iss b/installer/SingleFile/Windows.iss new file mode 100644 index 0000000..4564b89 --- /dev/null +++ b/installer/SingleFile/Windows.iss @@ -0,0 +1,23 @@ +[Setup] +AppName=GitHubView +AppVersion=develop +DefaultDirName={pf}\GitHubView +VersionInfoCopyright=Copyright (c) 鸭鸭「カモ」 +AppPublisher=鸭鸭「カモ」 +AppPublisherURL=https://duckduckstudio.github.io/yazicbs.github.io/ +OutputDir=. +OutputBaseFilename=GitHubView-installer + +[Languages] +Name: "english"; MessagesFile: "compiler:Default.isl" +Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl" +Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl" + +[Files] +Source: "D:\a\GitHubView\GitHubView\output_SingleFile\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs + +[Run] +Filename: "{sys}\cmd.exe"; Parameters: "/C setx PATH ""{app};%PATH%"" /M"; Flags: runhidden + +[UninstallRun] +Filename: "{sys}\cmd.exe"; Parameters: "/C setx PATH ""%PATH:{app};=%"" /M"; Flags: runhidden; RunOnceId: UninstallSetPath diff --git a/installer/Windows.iss b/installer/Windows.iss index 00acf37..bac1c17 100644 --- a/installer/Windows.iss +++ b/installer/Windows.iss @@ -13,11 +13,8 @@ Name: "english"; MessagesFile: "compiler:Default.isl" Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl" Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl" -[Icons] -Name: "{commonstartmenu}\Programs\GitHubView"; Filename: "{app}\ghv.exe"; WorkingDir: "{app}" - [Files] -Source: "..\output\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +Source: "D:\a\GitHubView\GitHubView\output\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs [Run] Filename: "{sys}\cmd.exe"; Parameters: "/C setx PATH ""{app};%PATH%"" /M"; Flags: runhidden diff --git "a/\350\207\252\345\212\250\345\214\226\350\204\232\346\234\254/\344\277\256\346\224\271\346\236\266\346\236\204.py" "b/\350\207\252\345\212\250\345\214\226\350\204\232\346\234\254/\344\277\256\346\224\271\346\236\266\346\236\204.py" new file mode 100644 index 0000000..a8da98d --- /dev/null +++ "b/\350\207\252\345\212\250\345\214\226\350\204\232\346\234\254/\344\277\256\346\224\271\346\236\266\346\236\204.py" @@ -0,0 +1,40 @@ +import os +import sys + +def 替换文件内容(文件路径, 原文本, 新文本): + try: + # 读取文件内容 + with open(文件路径, 'r', encoding='utf-8') as f: + 内容 = f.read() + + # 替换文本 + 内容 = 内容.replace(原文本, 新文本) + + # 写回文件 + with open(文件路径, 'w', encoding='utf-8') as f: + f.write(内容) + except Exception as e: + print(f"[ERROR] 处理 {文件路径} 时出错: {e}") + sys.exit(1) + +if len(sys.argv) != 2: + print("[ERROR] 使用示例: python xxx.py <架构>") + sys.exit(1) + +架构 = sys.argv[1] +if (not 架构) or (架构 not in ["x86", "x64", "arm", "arm64", "amd64"]): + print(f"[ERROR] 架构为空或格式不正确,获取到的架构: {架构}") + sys.exit(1) +print(f"[INFO] 架构: {架构}") + +# 文件路径和替换规则 +文件和替换规则 = [ + (os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))), "installer", "SingleFile", "DEBIAN", "control"), '这是一个架构', 架构) +] + +# 执行替换操作 +for 文件路径, 原文本, 新文本 in 文件和替换规则: + 替换文件内容(文件路径, 原文本, 新文本) + +print("[INFO] 🎉 成功处理所有文件") +sys.exit(0) diff --git "a/\350\207\252\345\212\250\345\214\226\350\204\232\346\234\254/\344\277\256\346\224\271\347\211\210\346\234\254\345\217\267.py" "b/\350\207\252\345\212\250\345\214\226\350\204\232\346\234\254/\344\277\256\346\224\271\347\211\210\346\234\254\345\217\267.py" new file mode 100644 index 0000000..c77f4f3 --- /dev/null +++ "b/\350\207\252\345\212\250\345\214\226\350\204\232\346\234\254/\344\277\256\346\224\271\347\211\210\346\234\254\345\217\267.py" @@ -0,0 +1,43 @@ +import os +import sys + +def 替换文件内容(文件路径, 原文本, 新文本): + try: + # 读取文件内容 + with open(文件路径, 'r', encoding='utf-8') as f: + 内容 = f.read() + + # 替换文本 + 内容 = 内容.replace(原文本, 新文本) + + # 写回文件 + with open(文件路径, 'w', encoding='utf-8') as f: + f.write(内容) + except Exception as e: + print(f"[ERROR] 处理 {文件路径} 时出错: {e}") + sys.exit(1) + +if len(sys.argv) != 2: + print("[ERROR] 使用示例: python xxx.py <新版本号>") + sys.exit(1) + +新版本号 = sys.argv[1] +if (not 新版本号) or (新版本号.startswith('v')): + print(f"[ERROR] 新版本号为空或格式不正确,获取到的新版本号: {新版本号}") + sys.exit(1) +print(f"[INFO] 新版本号: {新版本号}") + +# 文件路径和替换规则 +文件和替换规则 = [ + (os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))), "ghv", "Program.cs"), 'Version = "develop"', f'Version = "{新版本号}"'), + (os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))), "installer", "Windows.iss"), 'AppVersion=develop', f'AppVersion={新版本号}'), + (os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))), "installer", "SingleFile", "Windows.iss"), 'AppVersion=develop', f'AppVersion={新版本号}'), + (os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))), "installer", "SingleFile", "DEBIAN", "control"), 'develop', 新版本号) +] + +# 执行替换操作 +for 文件路径, 原文本, 新文本 in 文件和替换规则: + 替换文件内容(文件路径, 原文本, 新文本) + +print("[INFO] 🎉 成功处理所有文件") +sys.exit(0)