@@ -9,18 +9,12 @@ inputs:
99 description : ' No scopes GitHub token for querying the API and downloading from winget-cli releases'
1010 required : false
1111 default : ' NONE'
12- wget_release_id :
13- description : ' Specify desired release-id of winget can be specified here. By default, a recent stable release will be selected by the action author. To see what versions are available, look into https://api.github.com/repos/microsoft/winget-cli/releases'
14- required : false
15- default : ' 164835566' # latest can be used here
1612
1713outputs :
1814 winget-version :
1915 description : " The version of winget installed"
2016 value : ${{ steps.winget-version.outputs.winget-version }}
2117runs :
22- # Hacked together https://github.com/microsoft/winget-cli/issues/1861#issuecomment-1352784247
23- # https://github.com/microsoft/winget-cli/issues/700#issuecomment-874084714
2418 using : composite
2519 steps :
2620 - name : Check runner OS is Windows
@@ -30,129 +24,25 @@ runs:
3024 echo "[ERROR] This action only runs on Windows runner, Current runner: ${{ runner.os }}"
3125 exit 1
3226
33- - name : Check OS Version
34- shell : powershell
35- id : os_check
36- run : |
37- $version = (Get-WmiObject Win32_OperatingSystem).Caption
38- echo "version=${version}" >> $env:GITHUB_OUTPUT
39- echo $version
40-
41- - name : Check if winget is already installed
42- shell : powershell
43- id : wget_check
44- run : |
45- $available = [bool](Get-Command winget -ErrorAction SilentlyContinue)
46- echo "available=${available}" >> $env:GITHUB_OUTPUT
47- echo $available
48-
49- - name : Upgrade winget if installed
50- if : steps.wget_check.outputs.available == 'True'
51- shell : powershell
52- run : winget upgrade winget --accept-package-agreements --accept-source-agreements --disable-interactivity --silent --ignore-warnings
53-
54- - name : Download Microsoft.UI.Xaml v2.8.6
55- if : steps.wget_check.outputs.available == 'False'
56- shell : powershell
57- run : |
58- $ProgressPreference = 'SilentlyContinue'
59- Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.8.6 -OutFile .\microsoft.ui.xaml.2.8.6.zip
60- Expand-Archive .\microsoft.ui.xaml.2.8.6.zip
61-
62- - name : Download Microsoft.VCLibs.x64.14.00.Desktop
63- if : steps.wget_check.outputs.available == 'False'
64- shell : powershell
65- run : |
66- $ProgressPreference = 'SilentlyContinue'
67- Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx
68-
69- - name : Determine Latest winget release via GitHub API
70- if : steps.wget_check.outputs.available == 'False'
71- id : github_api
72- shell : powershell
73- run : |
74- $ProgressPreference = 'SilentlyContinue'
75- if ("${{ inputs.GITHUB_TOKEN }}" -ne "NONE") {
76- $headers = @{ "Authorization" = "Bearer ${{ inputs.GITHUB_TOKEN }}" }
77- Write-Host "Token present"
78- } else {
79- $headers = @{}
80- Write-Host "No token present"
81- }
82-
83- $releaseURL = "https://api.github.com/repos/microsoft/winget-cli/releases/${{ inputs.wget_release_id }}"
84- $gitHubReleasesResponse = Invoke-RestMethod $releaseURL -Headers $headers
85- $wingetReleaseAssets = $gitHubReleasesResponse.assets
86- $latestWingetMsixBundleUri = $wingetReleaseAssets.browser_download_url | Where-Object {$_.EndsWith(".msixbundle")}
87- $latestWingetLicenseXmlUri = $wingetReleaseAssets.browser_download_url | Where-Object {$_.EndsWith("License1.xml")}
88- Write-Host "latest_winget_msix_bundle_uri=$latestWingetMsixBundleUri"
89- Write-Host "latest_winget_license_xml_uri=$latestWingetLicenseXmlUri"
90- Write-Output "latest_winget_msix_bundle_uri=$latestWingetMsixBundleUri" >> $Env:GITHUB_OUTPUT
91- Write-Output "latest_winget_license_xml_uri=$latestWingetLicenseXmlUri" >> $Env:GITHUB_OUTPUT
92-
93- - name : Download winget
94- if : steps.wget_check.outputs.available == 'False'
95- shell : powershell
96- run : |
97- $ProgressPreference = 'SilentlyContinue'
98- Invoke-WebRequest -Headers $headers -Uri "${{ steps.github_api.outputs.latest_winget_msix_bundle_uri }}" -OutFile "./winget.msixbundle"
99-
100- - name : Download License
101- if : steps.wget_check.outputs.available == 'False'
102- shell : powershell
103- run : |
104- $ProgressPreference = 'SilentlyContinue'
105- Invoke-WebRequest -Headers $headers -Uri "${{ steps.github_api.outputs.latest_winget_license_xml_uri }}" -OutFile "./winget_License1.xml"
106-
107- - name : Install Microsoft.UI.Xaml v2.8.6
108- if : steps.os_check.outputs.version == 'Microsoft Windows Server 2022 Datacenter'
109- shell : powershell
110- run : |
111- Add-AppxPackage .\microsoft.ui.xaml.2.8.6\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.8.appx
112-
113- - name : Install Microsoft.VCLibs.x64.14.00.Desktop
114- if : steps.os_check.outputs.version == 'Microsoft Windows Server 2022 Datacenter'
115- shell : powershell
116- run : |
117- Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx
118-
119- - name : Install winget
120- if : steps.wget_check.outputs.available == 'False'
121- shell : powershell
122- run : |
123- echo "PROVISIONING WINGET"
124- Add-AppxProvisionedPackage -Online -PackagePath ./winget.msixbundle -LicensePath ./winget_License1.xml
125-
126- - name : Installing Winget
127- if : steps.wget_check.outputs.available == 'False'
128- shell : powershell
129- run : |
130- echo "INSTALLING WINGET"
131- $ProgressPreference = 'SilentlyContinue'
132- Add-AppxPackage .\winget.msixbundle
133-
134- - name : Cleanup Downloads
135- if : steps.wget_check.outputs.available == 'False'
27+ - name : Install Microsoft.WinGet.Client module
13628 shell : powershell
13729 run : |
138- rm Microsoft.VCLibs.x64.14.00.Desktop.appx
139- rm ./winget_License1.xml
140- rm ./winget.msixbundle
141- Remove-Item -Recurse -Force .\microsoft.ui.xaml.2.8.6
30+ $ErrorActionPreference = 'Stop'
31+ Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
32+ # Make sure the NuGet provider & PSGallery are ready
33+ Install-PackageProvider -Name NuGet -Force -Confirm:$false
34+ Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
35+ # Install/refresh the WinGet PowerShell client
36+ Install-Module Microsoft.WinGet.Client -Force -Scope CurrentUser
37+ Import-Module Microsoft.WinGet.Client -Force
14238
143- - name : Wait to allow Installation to Finalize
144- if : steps.wget_check.outputs.available == 'False'
39+ - name : Ensure WinGet (App Installer) is installed/updated
14540 shell : powershell
14641 run : |
147- foreach ($i in 1..60) {
148- Start-Sleep -Seconds 1
149- Write-Host "Waiting for winget to install... ${i}"
150- if (Get-Command winget -ErrorAction SilentlyContinue) {
151- break
152- }
153- }
42+ $ErrorActionPreference = 'Stop'
43+ Repair-WinGetPackageManager -Latest -Force -Verbose
15444
155- - name : Output winget Version
45+ - name : Output winget version
15646 id : winget-version
15747 shell : powershell
15848 run : |
0 commit comments