Skip to content

ci: use Install-PSResource instead of Install-Module for WinGet#622

Merged
wmmc88 merged 3 commits intomicrosoft:mainfrom
wmmc88:fix/psgallery-flake
Mar 20, 2026
Merged

ci: use Install-PSResource instead of Install-Module for WinGet#622
wmmc88 merged 3 commits intomicrosoft:mainfrom
wmmc88:fix/psgallery-flake

Conversation

@wmmc88
Copy link
Collaborator

@wmmc88 wmmc88 commented Mar 4, 2026

Replace Install-Module (PowerShellGet v2) with Install-PSResource (PSResourceGet, built into PowerShell 7.4+) for installing the Microsoft.WinGet.Client module. PSResourceGet has its own repository system that is independent of the legacy NuGet pipeline, avoiding transient PSGallery registration failures on freshly provisioned windows-2025 runners.

Also switches codeql.yaml to use the shared install-winget composite action instead of inlining its own Install-Module step.

Example failure: https://github.com/microsoft/windows-drivers-rs/actions/runs/22659747111/job/65677070595?pr=621

Upstream issue: actions/runner-images#13758

Stress-tested in #626 (expanded LLVM matrix).

Copilot AI review requested due to automatic review settings March 4, 2026 08:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Guards Windows CI against intermittently missing PowerShell Gallery registration on windows-2025 runners by re-registering the default PS repositories before installing Microsoft.WinGet.Client.

Changes:

  • Add a preflight check for PSGallery registration and call Register-PSRepository -Default when missing.
  • Apply the same workaround in both the CodeQL workflow and the install-winget composite action.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
.github/workflows/codeql.yaml Adds a PSGallery-registration guard before installing the WinGet PowerShell module in the CodeQL job.
.github/actions/install-winget/action.yaml Adds the same PSGallery-registration guard to the shared composite action.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wmmc88 wmmc88 force-pushed the fix/psgallery-flake branch 2 times, most recently from cb5c267 to fcc4578 Compare March 4, 2026 18:06
Copilot AI review requested due to automatic review settings March 4, 2026 18:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.41%. Comparing base (90903c6) to head (b111df0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #622   +/-   ##
=======================================
  Coverage   77.41%   77.41%           
=======================================
  Files          24       24           
  Lines        4853     4853           
  Branches     4853     4853           
=======================================
  Hits         3757     3757           
  Misses        979      979           
  Partials      117      117           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wmmc88 wmmc88 marked this pull request as draft March 5, 2026 01:55
@wmmc88 wmmc88 force-pushed the fix/psgallery-flake branch from fcc4578 to 57b0194 Compare March 5, 2026 02:48
Copilot AI review requested due to automatic review settings March 5, 2026 20:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wmmc88 wmmc88 force-pushed the fix/psgallery-flake branch from 31d6b7a to 57b0194 Compare March 5, 2026 21:05
Copilot AI review requested due to automatic review settings March 6, 2026 07:48
@wmmc88 wmmc88 force-pushed the fix/psgallery-flake branch from 57b0194 to 09ef591 Compare March 6, 2026 07:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

.github/actions/install-winget/action.yaml:179

  • Get-Module -ListAvailable Microsoft.WinGet.Client | Select-Object -First 1 is not guaranteed to return the highest installed version if multiple versions exist, so the logged Installed module version can be inaccurate. To make the output deterministic (and more useful for debugging), select the highest version explicitly (e.g., sort by Version descending) and consider handling the case where the module isn’t present to emit a clearer error.
        $moduleVersion = (Get-Module -ListAvailable Microsoft.WinGet.Client | Select-Object -First 1).Version.ToString()
        Write-Host "Installed module version: $moduleVersion"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wmmc88 wmmc88 force-pushed the fix/psgallery-flake branch from 09ef591 to 29d273a Compare March 6, 2026 08:09
@wmmc88 wmmc88 changed the title ci: guard against missing PSGallery on Windows runners ci: use Install-PSResource instead of Install-Module for WinGet Mar 6, 2026
Replace Install-Module (PowerShellGet v2) with Install-PSResource
(PSResourceGet, built into PowerShell 7.4+). PSResourceGet has its
own repository system that is independent of the legacy NuGet
pipeline, avoiding transient PSGallery registration failures on
freshly provisioned runners.

Also switch codeql.yaml to use the shared install-winget composite
action instead of inlining its own Install-Module step.

See actions/runner-images#13758
Copilot AI review requested due to automatic review settings March 7, 2026 19:30
@wmmc88 wmmc88 force-pushed the fix/psgallery-flake branch from 29d273a to 1006d38 Compare March 7, 2026 19:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

.github/actions/install-winget/action.yaml:144

  • Get-Module -ListAvailable ... | Select-Object -First 1 does not reliably return the version that was just installed (ordering isn’t guaranteed and multiple versions may be present). This can make the log incorrect and can mask cases where an older version is still the one being resolved. Prefer querying the installed resource via PSResourceGet (e.g., Get-InstalledPSResource -Name Microsoft.WinGet.Client) or, at minimum, sort the available module versions by Version descending before selecting.
        $moduleVersion = (Get-Module -ListAvailable Microsoft.WinGet.Client | Select-Object -First 1).Version.ToString()
        Write-Host "Installed module version: $moduleVersion"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wmmc88 wmmc88 marked this pull request as ready for review March 7, 2026 22:49
@wmmc88 wmmc88 requested a review from a team March 9, 2026 23:34
Alan632
Alan632 previously approved these changes Mar 16, 2026
leon-xd
leon-xd previously approved these changes Mar 19, 2026
Signed-off-by: Melvin Wang <melvin.mc.wang@gmail.com>
@wmmc88 wmmc88 dismissed stale reviews from leon-xd and Alan632 via d530b0a March 19, 2026 21:59
Copilot AI review requested due to automatic review settings March 19, 2026 21:59
@wmmc88 wmmc88 enabled auto-merge March 19, 2026 22:00
@leon-xd leon-xd self-requested a review March 19, 2026 22:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

.github/actions/install-winget/action.yaml:143

  • Install-PSResource calls here don’t use -ErrorAction Stop / try-catch, and the script then unconditionally dereferences the result of Get-InstalledPSResource. If installation fails (or returns no installed resources), this will either mask the real error or hit a null dereference when accessing .Version. Recommend making Install-PSResource failures terminating (e.g., -ErrorAction Stop and/or $ErrorActionPreference='Stop') and validating a module was installed before reading its version.
            Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -TrustRepository -Quiet
          }
        }

        $moduleVersion = (Get-InstalledPSResource -Name Microsoft.WinGet.Client | Sort-Object Version -Descending | Select-Object -First 1).Version.ToString()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wmmc88 wmmc88 added this pull request to the merge queue Mar 19, 2026
Merged via the queue into microsoft:main with commit 73b7ba9 Mar 20, 2026
229 checks passed
@wmmc88 wmmc88 deleted the fix/psgallery-flake branch March 20, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants