diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 41d1cd5..9031132 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,4 +1,4 @@ -name: Pack Releases +name: 发布和构建 on: workflow_dispatch: @@ -8,13 +8,16 @@ on: required: true default: 2.3.3 release: - types: [ published ] + types: [published] -permissions: - contents: write +permissions: {} + +env: + PYTHONIOENCODING: utf-8 jobs: build: + name: 构建安装程序和压缩包 runs-on: windows-latest steps: @@ -29,8 +32,8 @@ jobs: python-version: 3.x - name: 更新版本号 + shell: pwsh env: - PYTHONIOENCODING: utf-8 GITHUB_EVENT_INPUTS_VERSION: ${{ github.event.inputs.version }} # 前面已经配置过 Python 了,这个脚本只用 os 和 sys 这两个标准库,不用再装依赖 run: |- @@ -56,8 +59,6 @@ jobs: - name: 安装依赖 shell: pwsh - env: - PYTHONIOENCODING: utf-8 # 环境配置的依赖文件中含有打包所需依赖 run: |- pip install -r "requirements.txt" @@ -75,55 +76,81 @@ jobs: - name: 整理源码 # 整理文件 > 压缩文件 > 清理工作目录 - env: - PYTHONIOENCODING: utf-8 - shell: bash + shell: pwsh run: |- - cp -v LICENSE src/LICENSE - mkdir Release - mkdir Release/src - cp -rv src/ Release - cp -v LICENSE Release/src - cp -v requirements.txt Release/src + Copy-Item -Path "LICENSE" -Destination "src/LICENSE" -Verbose + New-Item -ItemType Directory -Path "Release" -Verbose + New-Item -ItemType Directory -Path "Release/src" -Verbose + Copy-Item -Recurse -Path "src/*" -Destination "Release/src" + Copy-Item -Path "LICENSE" -Destination "Release/src" -Verbose + Copy-Item -Path "requirements.txt" -Destination "Release/src" -Verbose # 压缩源码到 Release,7z 和 zip - 7z a -t7z Release/Sundry-src.7z Release/src - 7z a -tzip Release/Sundry-src.zip Release/src + 7z a -t7z Release/Sundry-src.7z ./Release/src/* + 7z a -tzip Release/Sundry-src.zip ./Release/src/* - name: 制作安装程序和打包后的压缩包 - shell: bash - env: - PYTHONIOENCODING: utf-8 + shell: pwsh # 这里是直接打包过去的,不用管 sundry.ps1 run: |- - mkdir Release/pack - cp -v src/fun.txt Release/pack - cp -v LICENSE Release/pack - echo ======================================== + New-Item -ItemType Directory -Path "Release/pack" -Verbose + Copy-Item -Path "src/fun.txt" -Destination "Release/pack" -Verbose + Copy-Item -Path "LICENSE" -Destination "Release/pack" -Verbose + Write-Host "========================================" python "自动化脚本/png-2-ico.py" pyinstaller --onefile --distpath="Release/pack" --name="sundry.exe" "src/sundry.py" --upx-dir="upx" -i "icon/Sundry.ico" - echo ======================================== - 7z a -t7z Release/Sundry.7z Release/pack - 7z a -tzip Release/Sundry.zip Release/pack - echo ======================================== - curl -o "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl" "https://raw.githubusercontent.com/jrsoftware/issrc/main/Files/Languages/Unofficial/ChineseSimplified.isl" + Write-Host "========================================" + 7z a -t7z Release/Sundry.7z ./Release/pack/* + 7z a -tzip Release/Sundry.zip ./Release/pack/* + Write-Host "========================================" + if ((Get-Date) -le (Get-Date "2026-06-29")) { + Write-Host "通过 GitHub API 下载中文翻译..." + $apiUrl = "https://api.github.com/repos/jrsoftware/issrc/contents/Files/Languages/ChineseSimplified.isl?ref=main" + $downloadPath = "C:\Program Files (x86)\Inno Setup 6\Languages\ChineseSimplified.isl" + Invoke-WebRequest -Uri $apiUrl -Headers @{ "Accept" = "application/vnd.github.raw+json" } -OutFile $downloadPath + + Write-Host "校验下载文件哈希值..." + $expected = "8131FB1DB160E9502889351FA524D1BF693E231EBC90C8D9C1460056663B6450" + $actual = (Get-FileHash -Path $downloadPath -Algorithm SHA256).Hash.ToUpper() + if ($actual -ne $expected.ToUpper()) { + Write-Error "SHA256 哈希值不匹配\n预期: $expected\n实际: $actual" + exit -2145099774 + } + Write-Host "哈希值校验成功" + } else { + Write-Error "Inno Setup 7.0.2 应该今天会发布,请使用包含官方翻译的新版本" + exit -1 + } iscc installer.iss - name: 上传构建文件 - if: ${{ github.event_name == 'workflow_dispatch' }} uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: Release path: Release/** - - name: 整理发行版文件 - if: ${{ github.event_name != 'workflow_dispatch' }} - shell: bash + publish: + name: 发布发行版 + needs: build + runs-on: windows-latest + if: ${{ github.event_name == 'release' }} + + permissions: + contents: write # 发布发行版 + + steps: + - name: 下载构建文件 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: Release + path: Release + + - name: 移除中间产物 + shell: pwsh run: |- - rm -rv Release/pack - rm -rv Release/src + Remove-Item -Recurse "Release/pack" -Verbose + Remove-Item -Recurse "Release/src" -Verbose - name: 发布至发行版 - if: ${{ github.event_name != 'workflow_dispatch' }} - uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0 - with: - files: Release/** + env: + GH_TOKEN: ${{ github.token }} + run: gh release upload "$env:GITHUB_REF_NAME" "Release/*" diff --git a/installer.iss b/installer.iss index 20a699f..dd6143f 100644 --- a/installer.iss +++ b/installer.iss @@ -22,7 +22,7 @@ Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.i Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl" [Files] -Source: "Release\pack\*"; DestDir: "{app}"; Flags: recursesubdirs +Source: "Release\pack\*"; DestDir: "{app}"; [Run] Filename: "{sys}\cmd.exe"; Parameters: "/C setx PATH ""{app};%PATH%"" /M"; Flags: runhidden