Publish to Winget #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to Winget | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to publish (e.g., 1.0.25)' | |
| required: true | |
| type: string | |
| jobs: | |
| publish: | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install wingetcreate | |
| shell: pwsh | |
| run: | | |
| Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe | |
| - name: Validate release exists | |
| shell: pwsh | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| $release = gh release view "v${{ inputs.version }}" --repo open-cli-collective/google-readonly --json tagName 2>&1 | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Release v${{ inputs.version }} not found" | |
| exit 1 | |
| } | |
| Write-Host "Found release v${{ inputs.version }}" | |
| - name: Check if manifest exists in winget-pkgs | |
| id: check-manifest | |
| shell: pwsh | |
| run: | | |
| $response = Invoke-WebRequest -Uri "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/o/OpenCLICollective/google-readonly" -Method Head -SkipHttpErrorCheck | |
| if ($response.StatusCode -eq 200) { | |
| Write-Host "Manifest exists - will use wingetcreate update" | |
| echo "exists=true" >> $env:GITHUB_OUTPUT | |
| } else { | |
| Write-Host "Manifest does not exist - will use wingetcreate new" | |
| echo "exists=false" >> $env:GITHUB_OUTPUT | |
| } | |
| - name: Get checksums from release | |
| shell: pwsh | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| $version = "${{ inputs.version }}" | |
| gh release download "v$version" --repo open-cli-collective/google-readonly --pattern "checksums.txt" --dir . | |
| $checksums = Get-Content checksums.txt | |
| $x64Hash = ($checksums | Select-String "windows_amd64.zip").Line.Split()[0] | |
| $arm64Hash = ($checksums | Select-String "windows_arm64.zip").Line.Split()[0] | |
| Write-Host "x64 SHA256: $x64Hash" | |
| Write-Host "arm64 SHA256: $arm64Hash" | |
| echo "X64_HASH=$x64Hash" >> $env:GITHUB_ENV | |
| echo "ARM64_HASH=$arm64Hash" >> $env:GITHUB_ENV | |
| - name: Update manifest (existing package) | |
| if: steps.check-manifest.outputs.exists == 'true' | |
| shell: pwsh | |
| run: | | |
| $version = "${{ inputs.version }}" | |
| $x64 = "https://github.com/open-cli-collective/google-readonly/releases/download/v$version/gro_v${version}_windows_amd64.zip" | |
| $arm64 = "https://github.com/open-cli-collective/google-readonly/releases/download/v$version/gro_v${version}_windows_arm64.zip" | |
| Write-Host "Updating existing manifest to version $version" | |
| ./wingetcreate.exe update OpenCLICollective.google-readonly --version $version --urls $x64 $arm64 --submit --token ${{ secrets.WINGET_GITHUB_TOKEN }} | |
| - name: Create manifest (new package) | |
| if: steps.check-manifest.outputs.exists == 'false' | |
| shell: pwsh | |
| run: | | |
| $version = "${{ inputs.version }}" | |
| $manifestDir = "manifests" | |
| New-Item -ItemType Directory -Path $manifestDir -Force | Out-Null | |
| # Update version manifest | |
| $versionManifest = Get-Content "packaging/winget/OpenCLICollective.google-readonly.yaml" -Raw | |
| $versionManifest = $versionManifest -replace "0\.0\.0", $version | |
| Set-Content "$manifestDir/OpenCLICollective.google-readonly.yaml" $versionManifest | |
| # Update locale manifest | |
| $localeManifest = Get-Content "packaging/winget/OpenCLICollective.google-readonly.locale.en-US.yaml" -Raw | |
| $localeManifest = $localeManifest -replace "0\.0\.0", $version | |
| Set-Content "$manifestDir/OpenCLICollective.google-readonly.locale.en-US.yaml" $localeManifest | |
| # Update installer manifest with version and real checksums | |
| $installerManifest = Get-Content "packaging/winget/OpenCLICollective.google-readonly.installer.yaml" -Raw | |
| $installerManifest = $installerManifest -replace "0\.0\.0", $version | |
| # Replace checksums one at a time using .NET regex (PowerShell -replace doesn't support count) | |
| $regex = [regex]"0{64}" | |
| $installerManifest = $regex.Replace($installerManifest, $env:X64_HASH, 1) | |
| $installerManifest = $regex.Replace($installerManifest, $env:ARM64_HASH, 1) | |
| Set-Content "$manifestDir/OpenCLICollective.google-readonly.installer.yaml" $installerManifest | |
| Write-Host "Generated manifests:" | |
| Get-ChildItem $manifestDir | ForEach-Object { Write-Host " $_" } | |
| Write-Host "`nValidating manifests..." | |
| winget validate --manifest $manifestDir | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Error "Manifest validation failed" | |
| exit 1 | |
| } | |
| Write-Host "Validation passed!" | |
| Write-Host "`nSubmitting new package to Winget..." | |
| ./wingetcreate.exe submit --token ${{ secrets.WINGET_GITHUB_TOKEN }} $manifestDir |