| 1 | name: Windows Release for WinGet |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | tags: |
| 6 | - "ver.*" |
| 7 | workflow_dispatch: |
| 8 | inputs: |
| 9 | version: |
| 10 | description: "Release version or tag, for example 1.2.0, 1.2.1-rc1, 1.2.1-alpha1, or ver.1.2.0" |
| 11 | required: false |
| 12 | sign_windows_binaries: |
| 13 | description: "Sign Windows binaries with SignPath before packaging" |
| 14 | required: true |
| 15 | type: boolean |
| 16 | default: false |
| 17 | signpath_signing_policy_slug: |
| 18 | description: "SignPath signing policy slug to use when signing is enabled" |
| 19 | required: true |
| 20 | type: string |
| 21 | default: test-signing |
| 22 | |
| 23 | concurrency: |
| 24 | group: ${{ github.workflow }}-${{ github.ref }} |
| 25 | cancel-in-progress: true |
| 26 | |
| 27 | env: |
| 28 | SIGNPATH_PROJECT_SLUG: OpenCC |
| 29 | |
| 30 | jobs: |
| 31 | build-release: |
| 32 | runs-on: windows-2022 |
| 33 | permissions: |
| 34 | actions: read |
| 35 | contents: write |
| 36 | steps: |
| 37 | - uses: actions/checkout@v5 |
| 38 | with: |
| 39 | fetch-depth: 0 |
| 40 | |
| 41 | - uses: ilammy/msvc-dev-cmd@v1 |
| 42 | with: |
| 43 | arch: amd64 |
| 44 | |
| 45 | - name: Resolve version |
| 46 | id: version |
| 47 | shell: pwsh |
| 48 | env: |
| 49 | INPUT_VERSION: ${{ github.event.inputs.version }} |
| 50 | GIT_REF_TYPE: ${{ github.ref_type }} |
| 51 | GIT_REF_NAME: ${{ github.ref_name }} |
| 52 | run: | |
| 53 | $value = $env:INPUT_VERSION |
| 54 | if (-not $value -and $env:GIT_REF_TYPE -eq "tag") { |
| 55 | $value = $env:GIT_REF_NAME |
| 56 | } |
| 57 | if (-not $value) { |
| 58 | $clean = "" |
| 59 | } elseif ($value.StartsWith("ver.")) { |
| 60 | $clean = $value.Substring(4) |
| 61 | } elseif ($value.StartsWith("v")) { |
| 62 | $clean = $value.Substring(1) |
| 63 | } else { |
| 64 | $clean = $value |
| 65 | } |
| 66 | "value=$clean" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append |
| 67 | |
| 68 | - name: Build portable release staging |
| 69 | shell: pwsh |
| 70 | env: |
| 71 | RELEASE_VERSION: ${{ steps.version.outputs.value }} |
| 72 | GITHUB_REPO: ${{ github.repository }} |
| 73 | run: | |
| 74 | ./scripts/release-windows-winget.ps1 ` |
| 75 | -Version "$env:RELEASE_VERSION" ` |
| 76 | -OutputDir release ` |
| 77 | -GitHubRepository "$env:GITHUB_REPO" ` |
| 78 | -PackageIdentifier "BYVoid.OpenCC" ` |
| 79 | -Publisher "BYVoid" ` |
| 80 | -PrepareOnly |
| 81 | |
| 82 | - name: Create unsigned SignPath input |
| 83 | if: ${{ github.event_name == 'workflow_dispatch' && inputs.sign_windows_binaries }} |
| 84 | shell: pwsh |
| 85 | run: | |
| 86 | New-Item -ItemType Directory -Force -Path release/signpath | Out-Null |
| 87 | Compress-Archive ` |
| 88 | -Path "release/staging/*" ` |
| 89 | -DestinationPath "release/signpath/opencc-winget-portable-win32-x64.zip" ` |
| 90 | -CompressionLevel Optimal |
| 91 | |
| 92 | - name: Upload unsigned SignPath input |
| 93 | if: ${{ github.event_name == 'workflow_dispatch' && inputs.sign_windows_binaries }} |
| 94 | id: upload-unsigned-signpath-input |
| 95 | uses: actions/upload-artifact@v7 |
| 96 | with: |
| 97 | name: unsigned-opencc-winget-portable-win32-x64 |
| 98 | path: release/signpath/opencc-winget-portable-win32-x64.zip |
| 99 | archive: false |
| 100 | if-no-files-found: error |
| 101 | |
| 102 | - name: Submit SignPath signing request |
| 103 | if: ${{ github.event_name == 'workflow_dispatch' && inputs.sign_windows_binaries }} |
| 104 | uses: signpath/github-action-submit-signing-request@v2 |
| 105 | with: |
| 106 | api-token: ${{ secrets.SIGNPATH_API_TOKEN }} |
| 107 | organization-id: ${{ secrets.SIGNPATH_ORGANIZATION_ID }} |
| 108 | project-slug: ${{ env.SIGNPATH_PROJECT_SLUG }} |
| 109 | signing-policy-slug: ${{ inputs.signpath_signing_policy_slug || 'test-signing' }} |
| 110 | artifact-configuration-slug: opencc-winget-portable-win32-x64 |
| 111 | github-artifact-id: ${{ steps.upload-unsigned-signpath-input.outputs.artifact-id }} |
| 112 | wait-for-completion: true |
| 113 | skip-decompress: true |
| 114 | output-artifact-directory: release/signpath-signed |
| 115 | |
| 116 | - name: Restore signed portable staging |
| 117 | if: ${{ github.event_name == 'workflow_dispatch' && inputs.sign_windows_binaries }} |
| 118 | shell: pwsh |
| 119 | run: | |
| 120 | $signedRoot = "release/signpath-signed" |
| 121 | $stagingRoot = "release/staging" |
| 122 | $signedZip = Get-ChildItem -Path $signedRoot -Filter "*.zip" -Recurse | Select-Object -First 1 |
| 123 | $signedContentRoot = Get-ChildItem -Path $signedRoot -Directory -Recurse | |
| 124 | Where-Object { Test-Path (Join-Path $_.FullName "bin") } | |
| 125 | Select-Object -First 1 |
| 126 | |
| 127 | Remove-Item -Recurse -Force $stagingRoot -ErrorAction SilentlyContinue |
| 128 | New-Item -ItemType Directory -Force -Path $stagingRoot | Out-Null |
| 129 | |
| 130 | if ($signedZip) { |
| 131 | Expand-Archive -Path $signedZip.FullName -DestinationPath $stagingRoot -Force |
| 132 | } elseif (Test-Path (Join-Path $signedRoot "bin")) { |
| 133 | Copy-Item -Path (Join-Path $signedRoot "*") -Destination $stagingRoot -Recurse -Force |
| 134 | } elseif ($signedContentRoot) { |
| 135 | Copy-Item -Path (Join-Path $signedContentRoot.FullName "*") -Destination $stagingRoot -Recurse -Force |
| 136 | } else { |
| 137 | throw "Unable to locate signed portable archive or extracted staging files under $signedRoot." |
| 138 | } |
| 139 | |
| 140 | - name: Verify signed portable files |
| 141 | if: ${{ github.event_name == 'workflow_dispatch' && inputs.sign_windows_binaries }} |
| 142 | shell: pwsh |
| 143 | run: | |
| 144 | $files = @( |
| 145 | "release/staging/bin/opencc.exe", |
| 146 | "release/staging/bin/opencc_dict.exe", |
| 147 | "release/staging/bin/opencc_phrase_extract.exe" |
| 148 | ) + (Get-ChildItem "release/staging/bin/plugins" -Filter "*.dll" | ForEach-Object { $_.FullName }) |
| 149 | |
| 150 | foreach ($file in $files) { |
| 151 | $signature = Get-AuthenticodeSignature -FilePath $file |
| 152 | if ($signature.SignerCertificate -eq $null) { |
| 153 | throw "Missing Authenticode signature: $file" |
| 154 | } |
| 155 | Write-Host "$file signed by $($signature.SignerCertificate.Subject); status: $($signature.Status)" |
| 156 | } |
| 157 | |
| 158 | - name: Build portable release and WinGet manifests |
| 159 | shell: pwsh |
| 160 | env: |
| 161 | RELEASE_VERSION: ${{ steps.version.outputs.value }} |
| 162 | GITHUB_REPO: ${{ github.repository }} |
| 163 | run: | |
| 164 | ./scripts/release-windows-winget.ps1 ` |
| 165 | -Version "$env:RELEASE_VERSION" ` |
| 166 | -OutputDir release ` |
| 167 | -GitHubRepository "$env:GITHUB_REPO" ` |
| 168 | -PackageIdentifier "BYVoid.OpenCC" ` |
| 169 | -Publisher "BYVoid" ` |
| 170 | -PackageOnly |
| 171 | |
| 172 | - name: Upload release artifacts |
| 173 | uses: actions/upload-artifact@v7 |
| 174 | with: |
| 175 | name: opencc-winget-release-${{ steps.version.outputs.value }} |
| 176 | path: | |
| 177 | release/*.zip |
| 178 | release/*.sha256 |
| 179 | release/winget-manifests/** |
| 180 | |
| 181 | - name: Upload to GitHub release |
| 182 | if: startsWith(github.ref, 'refs/tags/') |
| 183 | shell: bash |
| 184 | env: |
| 185 | GH_TOKEN: ${{ github.token }} |
| 186 | run: | |
| 187 | tag="${{ github.ref_name }}" |
| 188 | for i in $(seq 1 30); do |
| 189 | gh release view "$tag" --json isDraft > /dev/null 2>&1 && break |
| 190 | echo "Waiting for release $tag to be created ($i/30)..." |
| 191 | sleep 10 |
| 192 | done |
| 193 | gh release upload "$tag" \ |
| 194 | release/*.zip release/*.sha256 \ |
| 195 | --clobber |