Skip to content

Commit 36ebdf8

Browse files
committed
Switch to Powershell cmdlet and always install/upgrade to latest winget
1 parent 3740e4f commit 36ebdf8

File tree

3 files changed

+16
-163
lines changed

3 files changed

+16
-163
lines changed

.github/workflows/test_action.yml

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
steps:
2929
- name: Install winget
3030
id: install-winget
31-
uses: geldata/install-winget@main
31+
uses: geldata/install-winget@${{ github.ref }}
3232

3333
- name: Check Version
3434
shell: bash
@@ -43,7 +43,7 @@ jobs:
4343
run: winget install wingetcreate --disable-interactivity --accept-source-agreements --accept-package-agreements
4444

4545
test-job-with-token:
46-
name: Test Pinned Job with GitHub Token
46+
name: Test with GitHub Token
4747
strategy:
4848
fail-fast: false
4949
matrix:
@@ -57,7 +57,7 @@ jobs:
5757

5858
- name: Install winget
5959
id: install-winget
60-
uses: Cyberboss/install-winget@main
60+
uses: geldata/install-winget@${{ github.ref }}
6161
with:
6262
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6363

@@ -72,35 +72,3 @@ jobs:
7272
7373
- name: Install wingetcreate
7474
run: winget install wingetcreate --disable-interactivity --accept-source-agreements
75-
76-
test-latest-with-token:
77-
name: Test Latest Job with GitHub Token
78-
strategy:
79-
fail-fast: false
80-
matrix:
81-
os: [ 'windows-2022', 'windows-2025', 'windows-11-arm', 'windows-latest' ]
82-
repeat: [ 'a', 'b' ]
83-
runs-on: ${{ matrix.os }}
84-
steps:
85-
- name: Echo Runner OS version
86-
shell: powershell
87-
run: (Get-WmiObject Win32_OperatingSystem).Caption
88-
89-
- name: Install winget
90-
id: install-winget
91-
uses: Cyberboss/install-winget@main
92-
with:
93-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94-
wget_release_id: latest
95-
96-
- name: Check Version
97-
shell: bash
98-
run: |
99-
VERSION="${{ steps.install-winget.outputs.winget-version }}"
100-
if [ -z "$VERSION" ]; then
101-
exit 1
102-
fi
103-
echo $VERSION
104-
105-
- name: Install wingetcreate
106-
run: winget install wingetcreate --disable-interactivity --accept-source-agreements

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
uses: geldata/install-winget@v1
2323
with:
2424
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
wget_release_id: latest
2625
2726
- name: Install wingetcreate
2827
run: winget install wingetcreate --disable-interactivity --accept-source-agreements
@@ -36,10 +35,6 @@ The GitHub token to use when interacting with the GitHub API. Used to bypass una
3635

3736
**Recommendation is to set this to ${{ secrets.GITHUB_TOKEN }} or some other available token** as GitHub runners tend to often come with exhausted rate limits.
3837

39-
#### `wget_release_id` (Optional)
40-
41-
This is used to be able to pin (make immutable) the version of winget that is taken github. To see which versions (you need the release-id) is possible to use plese check the github API for the release of [winget-cli](https://github.com/microsoft/winget-cli) this can be checked by looking for the topmost `id:` attribute here: https://api.github.com/repos/microsoft/winget-cli/releases .
42-
4338
### Outputs
4439

4540
#### `winget-version`

action.yml

Lines changed: 13 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1713
outputs:
1814
winget-version:
1915
description: "The version of winget installed"
2016
value: ${{ steps.winget-version.outputs.winget-version }}
2117
runs:
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

Comments
 (0)