Add workflow to automatically submit to Winget#722
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a GitHub Actions workflow to automatically submit new releases to the WinGet community repository using the wingetcreate tool. The workflow triggers on release publication and uses a repository secret for authentication.
Key Changes:
- Adds automated WinGet package submission workflow triggered on release publication
- Implements logic to differentiate between stable and prerelease packages
- Downloads and executes wingetcreate to update package manifests with x64 and arm64 installers
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # winget-create is only supported on Windows | ||
| runs-on: windows-latest | ||
|
|
There was a problem hiding this comment.
[nitpick] Trailing whitespace present on this line.
| - name: Submit package using wingetcreate | ||
| run: | | ||
| # Set the package ID based on the release info | ||
| $packageId = if (${{ !github.event.release.prerelease }}) { "GitHub.Copilot" } else { "GitHub.Copilot.Prerelease" } |
There was a problem hiding this comment.
The PowerShell conditional expression is incorrect. Using ${{ !github.event.release.prerelease }} inside a PowerShell script will evaluate to a literal string "True" or "False" rather than a PowerShell boolean. This will cause the conditional to always evaluate to true (as non-empty strings are truthy).
Replace with:
$packageId = if ('${{ github.event.release.prerelease }}' -eq 'false') { "GitHub.Copilot" } else { "GitHub.Copilot.Prerelease" }| $packageId = if (${{ !github.event.release.prerelease }}) { "GitHub.Copilot" } else { "GitHub.Copilot.Prerelease" } | |
| $packageId = if ('${{ github.event.release.prerelease }}' -eq 'false') { "GitHub.Copilot" } else { "GitHub.Copilot.Prerelease" } |
|
|
||
| # Get installer info from release event | ||
| $assets = '${{ toJSON(github.event.release.assets) }}' | ConvertFrom-Json | ||
| $packageVersion = (${{ toJSON(github.event.release.tag_name) }}) |
There was a problem hiding this comment.
The toJSON function is unnecessary here and will add extra quotes around the tag name. The tag_name is already a string, so wrapping it with toJSON() and then assigning it to a PowerShell variable will result in a doubly-quoted string like "v1.0.0" instead of v1.0.0.
Replace with:
$packageVersion = '${{ github.event.release.tag_name }}'| $packageVersion = (${{ toJSON(github.event.release.tag_name) }}) | |
| $packageVersion = '${{ github.event.release.tag_name }}' |
| # This allows overrides to be used so that wingetcreate does not have to guess the architecture from the filename | ||
| $installerUrlx64 = $assets | Where-Object -Property name -like '*win32-x64.zip' | Select-Object -ExpandProperty browser_download_url | ||
| $installerUrlarm64 = $assets | Where-Object -Property name -like '*win32-arm64.zip' | Select-Object -ExpandProperty browser_download_url | ||
|
|
There was a problem hiding this comment.
Missing error handling if the installer URLs are not found. If the asset patterns don't match or the assets are missing, $installerUrlx64 or $installerUrlarm64 will be empty, causing the wingetcreate command to fail with unclear errors.
Consider adding validation:
if ([string]::IsNullOrEmpty($installerUrlx64) -or [string]::IsNullOrEmpty($installerUrlarm64)) {
Write-Error "Failed to find required installer assets"
exit 1
}| # Validate installer URLs | |
| if ([string]::IsNullOrEmpty($installerUrlx64) -or [string]::IsNullOrEmpty($installerUrlarm64)) { | |
| Write-Error "Failed to find required installer assets" | |
| exit 1 | |
| } | |
|
The workflow will fail until the prs in winget-pkgs are merged, which is why this was marked as draft |
Ah oops 😅 Looks like the PRs should make it in time before the next release thankfully 🤞 |
Yep! Looks like we should be good |
📖 Description
PR adds a GitHub action workflow for submitting the release to winget-pkgs repository.
GitHub Repository Secret
To add a personal access token (PAT), one can follow the steps listed in https://github.com/microsoft/winget-create?tab=readme-ov-file#github-personal-access-token-classic-permissions. Before this PR is merged, maintainers will need to create a repository secret with the name
WINGET_CREATE_GITHUB_TOKEN.🔗 References and Related Issues
See similar actions in the following repositories
🔍 How to Test
Action is tricky to test without a fork, but I've tested similar actions in private forks previously. One can test the wingetcreate command by omitting the --submit flag to see if the command will succeed
As a side note - if the workflow starts randomly failing, it is likely that whichever fork of winget-pkgs the repository secret is giving access to is outdated and needs to be synced with the upstream due to a bug in Octokit
✅ Checklist