-
Notifications
You must be signed in to change notification settings - Fork 20
116 lines (94 loc) · 5.38 KB
/
Copy pathwinget.yml
File metadata and controls
116 lines (94 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Submit release to the WinGet community repository
on:
workflow_call:
inputs:
package_version:
required: true
type: string
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() }
$tagVersion = ${{ inputs.package_version }}
# Get new installers from GitHub API
$github = Invoke-RestMethod -uri "https://api.github.com/repos/PowerShell/PowerShell/releases"
$targetRelease = $github | Where-Object { $_.tag_name -eq $tagVersion } | Select-Object -First 1
if ($targetRelease -eq $null)
{
throw "No Github release found for version $tagVersion"
}
$prereleaseVersion = $targetRelease.prerelease
$packageVersion = $targetRelease.tag_name.Trim('v')
$wingetPackageId = $prereleaseVersion ? "Microsoft.PowerShell.Preview" : "Microsoft.PowerShell"
$wingetPackageVersion = ""
if ($prereleaseVersion) {
# Map PowerShell release version to Winget package version: '7.6.0-preview.4' -> '7.6.0.4' or '7.6.0-rc.1' -> '7.6.0.101'
if ($packageVersion -notmatch "(\d+)\.(\d+)\.(\d+)-(preview|rc)\.(\d+)") {
throw "Version $packageVersion is not in expected format."
}
$major, $minor, $patch, $previewLabel, $revision = $Matches[1..5]
$revisionDigit = switch ($previewLabel) {
"preview" { $revision }
"rc" { [int]$revision + 100 }
default { throw "Version $packageVersion with preview label '$previewLabel' is not valid, the preview label must be either 'preview' or 'rc'." }
}
$wingetPackageVersion = "$major.$minor.$patch.$revisionDigit"
}
else {
# PowerShell stable versions have 3 digit version format, but Winget PackageVersion expects 4 digit version: '7.4.7' Winget PackageVersion needs to be '7.4.7.0'
$wingetPackageVersion = $packageVersion + ".0"
}
$assets = $targetRelease | Select-Object -ExpandProperty assets -First 1
$installerUrls = @()
if ($existingInstallerTypes -contains "wix") {
$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 $wingetPackageId `
--version $wingetPackageVersion `
--urls $installerUrls `
--submit