-
Notifications
You must be signed in to change notification settings - Fork 18
Reusable workflow for publishing package to WinGet #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mdanish-kh
wants to merge
1
commit into
PowerShell:master
Choose a base branch
from
mdanish-kh:winget-action
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| name: Submit release to the WinGet community repository | ||
|
|
||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| WINGET_CREATE_GITHUB_TOKEN: | ||
| description: 'GitHub token with permissions to create PRs against the WinGet community repository.' | ||
| required: true | ||
|
|
||
| jobs: | ||
| publish-winget: | ||
| name: Submit to WinGet repository | ||
|
|
||
| # winget-create is only supported on Windows | ||
| runs-on: windows-latest | ||
|
|
||
| # winget-create will read the following environment variable to access the GitHub token needed for submitting a PR | ||
| # See https://aka.ms/winget-create-token | ||
| env: | ||
| WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_CREATE_GITHUB_TOKEN }} | ||
|
|
||
| steps: | ||
| - name: Submit package using wingetcreate | ||
| run: | | ||
| # Download latest wingetcreate version | ||
| curl.exe -JLO https://aka.ms/wingetcreate/latest | ||
|
|
||
| # Run once to avoid output of first time telemetry notice in subsequent 'wingetcreate show' command | ||
| ./wingetcreate settings | Out-Null | ||
|
|
||
| # Get existing WinGet community repository installers info using wingetcreate | ||
| $json = (./wingetcreate show Microsoft.PowerShell -i --format json | Select -Skip 1 | ConvertFrom-Json) | ||
| $existingInstallerTypes = @( | ||
| $json.InstallerType | ||
| $json | ForEach-Object { $_.Installers.InstallerType } | ||
| ) | Select-Object -Unique | ForEach-Object { $_.ToLower() } | ||
|
|
||
| # Get new installers from GitHub API | ||
| $github = Invoke-RestMethod -uri "https://api.github.com/repos/PowerShell/PowerShell/releases" | ||
| $targetRelease = $github | Where-Object { -not $_.prerelease } | Select -First 1 | ||
| $assets = $targetRelease | Select-Object -ExpandProperty assets -First 1 | ||
| $x64InstallerUrlMSI = $assets | Where-Object -Property name -like '*win-x64.msi' | Select-Object -ExpandProperty browser_download_url | ||
| $x86InstallerUrlMSI = $assets | Where-Object -Property name -like '*win-x86.msi' | Select-Object -ExpandProperty browser_download_url | ||
| $arm64InstallerUrlMSI = $assets | Where-Object -Property name -like '*win-arm64.msi' | Select-Object -ExpandProperty browser_download_url | ||
|
|
||
| # URL strings with architecture overrides to pass to wingetcreate | ||
| $installerUrls = @( | ||
| "$x64InstallerUrlMSI|x64" | ||
| "$x86InstallerUrlMSI|x86" | ||
| "$arm64InstallerUrlMSI|arm" | ||
| "$arm64InstallerUrlMSI|arm64" | ||
| ) | ||
|
|
||
| # wingetcreate expects the number of installers in the update command to match | ||
| # the number of existing installers in the community repository manifest. | ||
| # If we have MSIX in the previous release at WinGet, add it in the update command as well | ||
| if ($existingInstallerTypes -contains "msix" -or $existingInstallerTypes -contains "appx") { | ||
| $msixInstallerUrl = $assets | Where-Object -Property name -like '*msixbundle' | Select-Object -ExpandProperty browser_download_url | ||
|
|
||
| # wingetcreate command will certainly fail if existing manifest has MSIX installer but we don't have it yet in the release assets | ||
| if (-not $msixInstallerUrl) { | ||
| Write-Error "Existing WinGet manifest contains MSIX installer, but no MSIXbundle found in the release assets. Re-run action when MSIX is available." | ||
| exit 1 | ||
| } | ||
|
|
||
| $installerUrls += $msixInstallerUrl | ||
| } | ||
|
|
||
| $packageVersion = $targetRelease.tag_name.Trim('v') | ||
|
|
||
| # Update package & submit PR using wingetcreate | ||
| ./wingetcreate.exe update Microsoft.PowerShell ` | ||
| --version $packageVersion ` | ||
| --urls $installerUrls ` | ||
| --submit | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.