From 22113b7cfa1c0aa7e2b64c069dda4bb48134237a Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Tue, 23 Dec 2025 15:43:42 -0500 Subject: [PATCH 1/2] ci: install winget via Repair-WinGetPackageManager --- .github/actions/install-winget/action.yaml | 78 ------------------- .github/workflows/build.yaml | 12 +-- .github/workflows/docs.yaml | 13 ++-- .github/workflows/lint.yaml | 13 ++-- .../workflows/local-development-makefile.yaml | 13 ++-- .github/workflows/test.yaml | 13 ++-- 6 files changed, 35 insertions(+), 107 deletions(-) delete mode 100644 .github/actions/install-winget/action.yaml diff --git a/.github/actions/install-winget/action.yaml b/.github/actions/install-winget/action.yaml deleted file mode 100644 index 5591288c0..000000000 --- a/.github/actions/install-winget/action.yaml +++ /dev/null @@ -1,78 +0,0 @@ -name: "Install Winget" -description: "Install winget on windows runners since its not installed by default: https://github.com/actions/runner-images/issues/6472" -inputs: - GITHUB_TOKEN: - description: "GitHub token to execute authenticated Github API requests (for higher rate limit)" - required: true -runs: - using: "composite" - steps: - - name: Get URIs for Winget v1.11.400 assets - 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 - - Expand-Archive -Path "$env:InstallWingetTempDir/DesktopAppInstaller_Dependencies.zip" -DestinationPath $env:InstallWingetTempDir/ -Force - - - name: Start Winget Installation for all Users - 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]) - - 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) - shell: pwsh - run: | - Add-AppxPackage $env:InstallWingetTempDir/winget.msixbundle - - - name: Wait for Completion of Winget Installation - shell: pwsh - run: | - while ((Get-Command * | Select-String winget)?.ToString() -ne "winget.exe") { - Start-Sleep -Seconds 1 - } - Write-Output "Winget Version: $(winget --version)" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 098bfd791..90056dd50 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -60,16 +60,18 @@ jobs: - 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 + - name: Install Winget + if: matrix.runner.name == 'windows-11-arm' + shell: pwsh + run: | + Repair-WinGetPackageManager -Latest -Force + Write-Output "Winget Version: $(winget --version)" + - name: Install LLVM ${{ matrix.llvm }} uses: ./.github/actions/install-llvm with: diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index fcf0385c4..5968833de 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -58,16 +58,17 @@ jobs: - 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 + - name: Install Winget + if: matrix.runner.name == 'windows-11-arm' + shell: pwsh + run: | + Repair-WinGetPackageManager -Latest -Force + Write-Output "Winget Version: $(winget --version)" + - name: Install LLVM ${{ matrix.llvm }} uses: ./.github/actions/install-llvm with: diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index b0d158291..a143e57db 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -61,16 +61,17 @@ jobs: - 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 + - name: Install Winget + if: matrix.runner.name == 'windows-11-arm' + shell: pwsh + run: | + Repair-WinGetPackageManager -Latest -Force + Write-Output "Winget Version: $(winget --version)" + - name: Install LLVM ${{ matrix.llvm }} uses: ./.github/actions/install-llvm with: diff --git a/.github/workflows/local-development-makefile.yaml b/.github/workflows/local-development-makefile.yaml index 1f7170f87..7e7d1d202 100644 --- a/.github/workflows/local-development-makefile.yaml +++ b/.github/workflows/local-development-makefile.yaml @@ -43,16 +43,17 @@ jobs: - 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 + - name: Install Winget + if: matrix.runner.name == 'windows-11-arm' + shell: pwsh + run: | + Repair-WinGetPackageManager -Latest -Force + Write-Output "Winget Version: $(winget --version)" + - name: Install LLVM ${{ matrix.llvm }} uses: ./.github/actions/install-llvm with: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2d245d923..5db567f63 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -50,16 +50,17 @@ jobs: - name: Checkout Repository 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 + - name: Install Winget + if: matrix.runner.arch == 'arm64' + shell: pwsh + run: | + Repair-WinGetPackageManager -Latest -Force + Write-Output "Winget Version: $(winget --version)" + - name: Install LLVM ${{ matrix.llvm }} uses: ./.github/actions/install-llvm with: From e5124bafd858b3cb3e319385d59235cee7a44bec Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Thu, 25 Dec 2025 11:41:15 -0500 Subject: [PATCH 2/2] address cr --- .github/actions/install-winget/action.yaml | 52 +++++++++++++++++++ .github/workflows/build.yaml | 15 ++---- .github/workflows/docs.yaml | 13 ++--- .github/workflows/lint.yaml | 13 ++--- .../workflows/local-development-makefile.yaml | 13 ++--- .github/workflows/test.yaml | 13 ++--- 6 files changed, 72 insertions(+), 47 deletions(-) create mode 100644 .github/actions/install-winget/action.yaml diff --git a/.github/actions/install-winget/action.yaml b/.github/actions/install-winget/action.yaml new file mode 100644 index 000000000..3ab55301f --- /dev/null +++ b/.github/actions/install-winget/action.yaml @@ -0,0 +1,52 @@ +name: Install Winget +description: Install the Microsoft.WinGet.Client module and optionally force Winget repair for images missing `winget-cli`. +inputs: + 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 + steps: + - name: Normalize inputs + id: normalize + shell: pwsh + run: | + $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 + } + } + + $outputLine = "force-cli-install=$normalized" + [System.IO.File]::AppendAllText($env:GITHUB_OUTPUT, "$outputLine`n", [System.Text.Encoding]::UTF8) + + - name: Install Winget PowerShell Module + shell: pwsh + run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force + + # 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: | + Repair-WinGetPackageManager -Latest -Force + Write-Output "Winget Version (via CLI): $(winget --version)" + + - name: Print Winget version (via Microsoft.WinGet.Client pwsh module) + shell: pwsh + run: | + Write-Output "Winget Version (via pwsh module): $(Get-WinGetVersion)" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 90056dd50..68383a73b 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -53,24 +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 PowerShell Module - shell: pwsh - run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force - - name: Install Winget - if: matrix.runner.name == 'windows-11-arm' - shell: pwsh - run: | - Repair-WinGetPackageManager -Latest -Force - Write-Output "Winget Version: $(winget --version)" + uses: ./.github/actions/install-winget + with: + # 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 diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 5968833de..3eba3bf56 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -58,16 +58,11 @@ jobs: - name: Checkout Repository uses: actions/checkout@v5 - - name: Install Winget PowerShell Module - shell: pwsh - run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force - - name: Install Winget - if: matrix.runner.name == 'windows-11-arm' - shell: pwsh - run: | - Repair-WinGetPackageManager -Latest -Force - Write-Output "Winget Version: $(winget --version)" + uses: ./.github/actions/install-winget + with: + # 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 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index a143e57db..9bd862f77 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -61,16 +61,11 @@ jobs: - name: Checkout Repository uses: actions/checkout@v5 - - name: Install Winget PowerShell Module - shell: pwsh - run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force - - name: Install Winget - if: matrix.runner.name == 'windows-11-arm' - shell: pwsh - run: | - Repair-WinGetPackageManager -Latest -Force - Write-Output "Winget Version: $(winget --version)" + uses: ./.github/actions/install-winget + with: + # 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 diff --git a/.github/workflows/local-development-makefile.yaml b/.github/workflows/local-development-makefile.yaml index 7e7d1d202..95ca8620f 100644 --- a/.github/workflows/local-development-makefile.yaml +++ b/.github/workflows/local-development-makefile.yaml @@ -43,16 +43,11 @@ jobs: - name: Checkout Repository uses: actions/checkout@v5 - - name: Install Winget PowerShell Module - shell: pwsh - run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force - - name: Install Winget - if: matrix.runner.name == 'windows-11-arm' - shell: pwsh - run: | - Repair-WinGetPackageManager -Latest -Force - Write-Output "Winget Version: $(winget --version)" + uses: ./.github/actions/install-winget + with: + # 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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5db567f63..4b29a7e99 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -50,16 +50,11 @@ jobs: - name: Checkout Repository uses: actions/checkout@v5 - - name: Install Winget PowerShell Module - shell: pwsh - run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force - - name: Install Winget - if: matrix.runner.arch == 'arm64' - shell: pwsh - run: | - Repair-WinGetPackageManager -Latest -Force - Write-Output "Winget Version: $(winget --version)" + uses: ./.github/actions/install-winget + with: + # 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