Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 38 additions & 64 deletions .github/actions/install-winget/action.yaml
Original file line number Diff line number Diff line change
@@ -1,78 +1,52 @@
name: "Install Winget"
description: "Install winget on windows runners since its not installed by default: https://github.com/actions/runner-images/issues/6472"
name: Install Winget
description: Install the Microsoft.WinGet.Client module and optionally force Winget repair for images missing `winget-cli`.
inputs:
GITHUB_TOKEN:
description: "GitHub token to execute authenticated Github API requests (for higher rate limit)"
required: true
force-cli-install:
description: Set to `true` to force install of latest Winget cli (only accepts `true` or `false`). This is useful on images where Winget may be absent (for example, Windows ARM64 partner images).
required: false
default: 'false'
runs:
using: "composite"
using: composite
steps:
- name: Get URIs for Winget v1.11.400 assets
- name: Normalize inputs
id: normalize
shell: pwsh
run: |
$AuthenticatedHeaders = @{ "Authorization" = "Bearer ${{ inputs.GITHUB_TOKEN }}" }

# Detect runner architecture
$Architecture = if ($env:RUNNER_ARCH -eq "ARM64") { "arm64" } else { "x64" }
Write-Host "Runner architecture: $Architecture"

# winget-cli release v1.11.400
# Define the winget-cli release tag to use
$WingetReleaseTag = "v1.11.400"
# Fetch release info by tag instead of magic number release ID
$ReleaseInfo = Invoke-RestMethod -Headers $AuthenticatedHeaders "https://api.github.com/repos/microsoft/winget-cli/releases/tags/$WingetReleaseTag"
$WingetDownloadUri = $ReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('.msixbundle') }
$WingetLicenseDownloadUri = $ReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('License1.xml') }
$WingetDependenciesZipDownloadUri = $ReleaseInfo.assets.browser_download_url | Where-Object { $_.EndsWith('DesktopAppInstaller_Dependencies.zip') }

# Print to logs
Write-Host "WingetDownloadUri=$WingetDownloadUri"
Write-Host "WingetLicenseDownloadUri=$WingetLicenseDownloadUri"
Write-Host "WingetDependenciesZipDownloadUri=$WingetDependenciesZipDownloadUri"

# Save output for next step
Write-Output "WingetDownloadUri=$WingetDownloadUri" >> $env:GITHUB_ENV
Write-Output "WingetLicenseDownloadUri=$WingetLicenseDownloadUri" >> $env:GITHUB_ENV
Write-Output "Architecture=$Architecture" >> $env:GITHUB_ENV
Write-Output "WingetDependenciesZipDownloadUri=$WingetDependenciesZipDownloadUri" >> $env:GITHUB_ENV
Write-Output "InstallWingetTempDir=$env:RUNNER_TEMP/install-winget" >> $env:GITHUB_ENV

- name: Download Winget Assets and Dependencies
shell: pwsh
run: |
$AuthenticatedHeaders = @{ "Authorization" = "Bearer ${{ inputs.GITHUB_TOKEN }}" }
New-Item -Type Directory $env:InstallWingetTempDir

# Download winget and license (architecture-agnostic)
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:WingetDownloadUri -OutFile $env:InstallWingetTempDir/winget.msixbundle
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:WingetLicenseDownloadUri -OutFile $env:InstallWingetTempDir/license.xml
Invoke-WebRequest -Headers $AuthenticatedHeaders -Uri $env:WingetDependenciesZipDownloadUri -OutFile $env:InstallWingetTempDir/DesktopAppInstaller_Dependencies.zip
$raw = "${{ inputs.force-cli-install }}"

$normalizedValue = $raw.Trim().ToLowerInvariant()

switch ($normalizedValue) {
'true' {
$normalized = 'true'
break
}
'false' {
$normalized = 'false'
break
}
default {
Write-Error "Invalid force-cli-install value '$raw'. Acceptable values: true or false."
exit 1
}
}

Expand-Archive -Path "$env:InstallWingetTempDir/DesktopAppInstaller_Dependencies.zip" -DestinationPath $env:InstallWingetTempDir/ -Force
$outputLine = "force-cli-install=$normalized"
[System.IO.File]::AppendAllText($env:GITHUB_OUTPUT, "$outputLine`n", [System.Text.Encoding]::UTF8)

- name: Start Winget Installation for all Users
- name: Install Winget PowerShell Module
shell: pwsh
run: |
# Use architecture-specific dependency paths
[string[]]$DependencyPaths = (Get-ChildItem -Path "$env:InstallWingetTempDir/$env:Architecture" -Filter '*.appx' -File -Force).FullName

$MicrosoftUIXamlDep = $($DependencyPaths[0])
$MicrosoftVCLibsDep = $($DependencyPaths[1])
run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force

Write-Host "Found Dependency $MicrosoftUIXamlDep"
Write-Host "Found Dependency $MicrosoftVCLibsDep"

Add-AppxProvisionedPackage -Online -PackagePath $env:InstallWingetTempDir/winget.msixbundle -LicensePath $env:InstallWingetTempDir/license.xml -DependencyPackagePath "$MicrosoftUIXamlDep", "$MicrosoftVCLibsDep"

- name: Install Winget for Current User (for better install diagnostics)
# Some hosted images (ex. https://github.com/actions/partner-runner-images/issues/95) do not ship winget-cli. Force install when requested.
- name: Ensure Winget is available
if: ${{ steps.normalize.outputs.force-cli-install == 'true' }}
shell: pwsh
run: |
Add-AppxPackage $env:InstallWingetTempDir/winget.msixbundle
Repair-WinGetPackageManager -Latest -Force
Write-Output "Winget Version (via CLI): $(winget --version)"

- name: Wait for Completion of Winget Installation
- name: Print Winget version (via Microsoft.WinGet.Client pwsh module)
shell: pwsh
run: |
while ((Get-Command * | Select-String winget)?.ToString() -ne "winget.exe") {
Start-Sleep -Seconds 1
}
Write-Output "Winget Version: $(winget --version)"
Write-Output "Winget Version (via pwsh module): $(Get-WinGetVersion)"
9 changes: 2 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,17 @@ jobs:
arch: amd64
- name: aarch64-pc-windows-msvc
arch: arm64

runs-on: ${{ matrix.runner.name }}

steps:
- name: Checkout Repository
uses: actions/checkout@v5

- name: Install Winget
if: matrix.runner.name == 'windows-11-arm'
uses: ./.github/actions/install-winget
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install Winget PowerShell Module
shell: pwsh
run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force
# windows-11-arm runner image does not include winget-cli (see https://github.com/actions/partner-runner-images/issues/95).
force-cli-install: ${{ matrix.runner.name == 'windows-11-arm' && 'true' || 'false' }}

- name: Install LLVM ${{ matrix.llvm }}
uses: ./.github/actions/install-llvm
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,10 @@ jobs:
uses: actions/checkout@v5

- name: Install Winget
if: matrix.runner.name == 'windows-11-arm'
uses: ./.github/actions/install-winget
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install Winget PowerShell Module
shell: pwsh
run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force
# windows-11-arm runner image does not include winget-cli (see https://github.com/actions/partner-runner-images/issues/95).
force-cli-install: ${{ matrix.runner.name == 'windows-11-arm' && 'true' || 'false' }}

- name: Install LLVM ${{ matrix.llvm }}
uses: ./.github/actions/install-llvm
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,10 @@ jobs:
uses: actions/checkout@v5

- name: Install Winget
if: matrix.runner.name == 'windows-11-arm'
uses: ./.github/actions/install-winget
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install Winget PowerShell Module
shell: pwsh
run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force
# windows-11-arm runner image does not include winget-cli (see https://github.com/actions/partner-runner-images/issues/95).
force-cli-install: ${{ matrix.runner.name == 'windows-11-arm' && 'true' || 'false' }}

- name: Install LLVM ${{ matrix.llvm }}
uses: ./.github/actions/install-llvm
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/local-development-makefile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ jobs:
uses: actions/checkout@v5

- name: Install Winget
if: matrix.runner.name == 'windows-11-arm'
uses: ./.github/actions/install-winget
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install Winget PowerShell Module
shell: pwsh
run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force
# windows-11-arm runner image does not include winget-cli (see https://github.com/actions/partner-runner-images/issues/95).
force-cli-install: ${{ matrix.runner.name == 'windows-11-arm' && 'true' || 'false' }}

- name: Install LLVM ${{ matrix.llvm }}
uses: ./.github/actions/install-llvm
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@ jobs:
uses: actions/checkout@v5

- name: Install Winget
if: matrix.runner.arch == 'arm64'
uses: ./.github/actions/install-winget
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install Winget PowerShell Module
shell: pwsh
run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force
# windows-11-arm runner image does not include winget-cli (see https://github.com/actions/partner-runner-images/issues/95).
force-cli-install: ${{ matrix.runner.name == 'windows-11-arm' && 'true' || 'false' }}

- name: Install LLVM ${{ matrix.llvm }}
uses: ./.github/actions/install-llvm
Expand Down
Loading