|
| 1 | +name: Publish to WinGet |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: 'Version to publish (e.g., 7.0.2)' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +env: |
| 14 | + WINGET_PKGS_FORK: ${{ secrets.WINGET_PKGS_FORK || 'ChangemakerStudios/winget-pkgs' }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + publish-winget: |
| 18 | + name: Publish to WinGet Repository |
| 19 | + runs-on: windows-latest |
| 20 | + # Only run on master branch releases (not pre-releases) |
| 21 | + if: | |
| 22 | + (github.event_name == 'release' && !github.event.release.prerelease && github.event.release.target_commitish == 'master') || |
| 23 | + github.event_name == 'workflow_dispatch' |
| 24 | +
|
| 25 | + permissions: |
| 26 | + contents: write |
| 27 | + pull-requests: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Determine version |
| 31 | + id: version |
| 32 | + run: | |
| 33 | + if ("${{ github.event_name }}" -eq "workflow_dispatch") { |
| 34 | + $version = "${{ inputs.version }}" |
| 35 | + } else { |
| 36 | + $version = "${{ github.event.release.tag_name }}" |
| 37 | + } |
| 38 | + echo "VERSION=$version" >> $env:GITHUB_OUTPUT |
| 39 | + echo "Publishing WinGet manifests for version: $version" |
| 40 | +
|
| 41 | + - name: Download winget manifests from release |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + run: | |
| 45 | + $version = "${{ steps.version.outputs.VERSION }}" |
| 46 | + $outputDir = "winget-manifests" |
| 47 | + New-Item -ItemType Directory -Path $outputDir -Force | Out-Null |
| 48 | +
|
| 49 | + Write-Host "Downloading WinGet manifests from release $version..." |
| 50 | + Write-Host "The Cake build (PrepareWinGetRelease task) generates these manifests and uploads them to the release." |
| 51 | + Write-Host "" |
| 52 | +
|
| 53 | + # The manifests are generated by the Cake build and uploaded to the release as assets |
| 54 | + $packageId = "ChangemakerStudios.PapercutSMTP" |
| 55 | + $manifestFiles = @( |
| 56 | + "$packageId.yaml", |
| 57 | + "$packageId.locale.en-US.yaml", |
| 58 | + "$packageId.installer.yaml" |
| 59 | + ) |
| 60 | +
|
| 61 | + $allSuccess = $true |
| 62 | + foreach ($file in $manifestFiles) { |
| 63 | + $url = "https://github.com/ChangemakerStudios/Papercut-SMTP/releases/download/$version/$file" |
| 64 | + Write-Host "Downloading: $url" |
| 65 | +
|
| 66 | + try { |
| 67 | + Invoke-WebRequest -Uri $url -OutFile "$outputDir/$file" -ErrorAction Stop |
| 68 | + Write-Host " ✓ Downloaded $file" |
| 69 | + } catch { |
| 70 | + Write-Error " ✗ Failed to download $file" |
| 71 | + Write-Error " Error: $_" |
| 72 | + $allSuccess = $false |
| 73 | + } |
| 74 | + } |
| 75 | +
|
| 76 | + if (-not $allSuccess) { |
| 77 | + Write-Error "" |
| 78 | + Write-Error "Failed to download one or more manifest files from the release." |
| 79 | + Write-Error "This usually means:" |
| 80 | + Write-Error " 1. The release was not created from the master branch (where PrepareWinGetRelease runs)" |
| 81 | + Write-Error " 2. The Cake build task 'PrepareWinGetRelease' failed during the build" |
| 82 | + Write-Error " 3. The DeployReleases task failed to upload the manifests" |
| 83 | + Write-Error "" |
| 84 | + Write-Error "Check the build logs for the release to verify the PrepareWinGetRelease task ran successfully." |
| 85 | + exit 1 |
| 86 | + } |
| 87 | +
|
| 88 | + Write-Host "" |
| 89 | + Write-Host "Successfully downloaded all manifests:" |
| 90 | + Get-ChildItem $outputDir | ForEach-Object { |
| 91 | + $content = Get-Content $_.FullName -Raw |
| 92 | + Write-Host " - $($_.Name) ($($_.Length) bytes)" |
| 93 | + } |
| 94 | +
|
| 95 | + - name: Validate manifests with winget |
| 96 | + run: | |
| 97 | + Write-Host "Validating manifests with winget CLI..." |
| 98 | + winget validate winget-manifests |
| 99 | + Write-Host "✓ Manifests are valid!" |
| 100 | +
|
| 101 | + - name: Upload manifests as artifact |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + name: winget-manifests-${{ steps.version.outputs.VERSION }} |
| 105 | + path: winget-manifests/ |
| 106 | + |
| 107 | + - name: Create PR to winget-pkgs repository |
| 108 | + env: |
| 109 | + GH_TOKEN: ${{ secrets.WINGET_PUBLISH_TOKEN }} |
| 110 | + run: | |
| 111 | + if ("${{ secrets.WINGET_PUBLISH_TOKEN }}" -eq "") { |
| 112 | + Write-Warning "WINGET_PUBLISH_TOKEN secret not set. Skipping automatic PR creation." |
| 113 | + Write-Host "" |
| 114 | + Write-Host "==========================================" |
| 115 | + Write-Host "Manual Submission Instructions" |
| 116 | + Write-Host "==========================================" |
| 117 | + Write-Host "" |
| 118 | + Write-Host "To enable automatic PR creation in the future:" |
| 119 | + Write-Host " 1. Fork https://github.com/microsoft/winget-pkgs" |
| 120 | + Write-Host " 2. Create a GitHub Personal Access Token with 'repo' and 'workflow' scopes" |
| 121 | + Write-Host " 3. Add it as WINGET_PUBLISH_TOKEN secret in your repository settings" |
| 122 | + Write-Host " 4. Optionally set WINGET_PKGS_FORK secret to 'YourUsername/winget-pkgs'" |
| 123 | + Write-Host "" |
| 124 | + Write-Host "To submit this release manually:" |
| 125 | + Write-Host " 1. Download the 'winget-manifests-${{ steps.version.outputs.VERSION }}' artifact from this workflow run" |
| 126 | + Write-Host " 2. Extract the three YAML files" |
| 127 | + Write-Host " 3. Fork/clone https://github.com/microsoft/winget-pkgs" |
| 128 | + Write-Host " 4. Copy files to: manifests/c/ChangemakerStudios/PapercutSMTP/${{ steps.version.outputs.VERSION }}/" |
| 129 | + Write-Host " 5. Create a pull request to microsoft/winget-pkgs" |
| 130 | + Write-Host "" |
| 131 | + exit 0 |
| 132 | + } |
| 133 | +
|
| 134 | + $version = "${{ steps.version.outputs.VERSION }}" |
| 135 | + $packageId = "ChangemakerStudios.PapercutSMTP" |
| 136 | + $forkRepo = "${{ env.WINGET_PKGS_FORK }}" |
| 137 | +
|
| 138 | + Write-Host "Creating pull request to microsoft/winget-pkgs..." |
| 139 | + Write-Host "Using fork: $forkRepo" |
| 140 | + Write-Host "" |
| 141 | +
|
| 142 | + # Configure git |
| 143 | + git config --global user.name "github-actions[bot]" |
| 144 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 145 | +
|
| 146 | + # Clone the fork |
| 147 | + Write-Host "Cloning fork repository..." |
| 148 | + git clone "https://x-access-token:${{ secrets.WINGET_PUBLISH_TOKEN }}@github.com/$forkRepo.git" winget-pkgs-fork |
| 149 | + cd winget-pkgs-fork |
| 150 | +
|
| 151 | + # Add upstream and fetch |
| 152 | + Write-Host "Adding upstream remote and fetching..." |
| 153 | + git remote add upstream https://github.com/microsoft/winget-pkgs.git |
| 154 | + git fetch upstream |
| 155 | +
|
| 156 | + # Create branch from upstream/master |
| 157 | + $branchName = "papercut-$version" |
| 158 | + Write-Host "Creating branch: $branchName" |
| 159 | + git checkout -b $branchName upstream/master |
| 160 | +
|
| 161 | + # Copy manifests to correct location |
| 162 | + $manifestPath = "manifests/c/ChangemakerStudios/PapercutSMTP/$version" |
| 163 | + Write-Host "Creating directory: $manifestPath" |
| 164 | + New-Item -ItemType Directory -Path $manifestPath -Force | Out-Null |
| 165 | +
|
| 166 | + Write-Host "Copying manifest files..." |
| 167 | + Copy-Item ../winget-manifests/* $manifestPath/ |
| 168 | +
|
| 169 | + # Commit and push |
| 170 | + Write-Host "Committing changes..." |
| 171 | + git add . |
| 172 | + git commit -m "New version: $packageId version $version" |
| 173 | +
|
| 174 | + Write-Host "Pushing to fork..." |
| 175 | + git push origin $branchName |
| 176 | +
|
| 177 | + # Create PR using GitHub CLI |
| 178 | + Write-Host "Creating pull request..." |
| 179 | + gh pr create ` |
| 180 | + --repo microsoft/winget-pkgs ` |
| 181 | + --title "New version: $packageId version $version" ` |
| 182 | + --body "This pull request updates Papercut SMTP to version $version.`n`n**Release Notes**: https://github.com/ChangemakerStudios/Papercut-SMTP/releases/tag/$version`n`nAutomatically generated by GitHub Actions from the Cake build system." ` |
| 183 | + --base master ` |
| 184 | + --head "$forkRepo`:$branchName" |
| 185 | +
|
| 186 | + Write-Host "" |
| 187 | + Write-Host "✓ Pull request created successfully!" |
| 188 | + Write-Host "The microsoft/winget-pkgs maintainers will review and merge the PR." |
0 commit comments