From d73e038d1eaa2bda9c8ddba0313847ff2782b1d6 Mon Sep 17 00:00:00 2001 From: Eduard Arbona Date: Fri, 6 Nov 2026 12:42:25 -0400 Subject: [PATCH 1/2] fix(website): the build no longer fails when the PowerShell Gallery hiccups The website job installs three pinned modules through build/Update-CommandReference.ps1 and one more in the workflow, every run, with no cache and no retry. When the Gallery cannot serve one of them the job fails with an error four steps removed from the cause, which reads as a problem with the branch being built. Measured on a run of my own PR #2702, whose diff is two test files and touches neither build/ nor website/: WARNING: Source Location 'http://www.powershellgallery.com:8080/api/v2/package/platyPS/0.14.2' is not valid. Install-Package: Package 'platyPS' failed to download. Import-Module: The specified module 'PlatyPS' with version '0.14.2' was not loaded because no valid module file was found in any module directory. New-MarkdownHelp: The term 'New-MarkdownHelp' is not recognized... NewSidebarIncludeFile: Cannot bind argument to parameter 'MarkdownFiles' because it is null. The Gallery handed the runner a source location on port 8080 over plain HTTP, the download failed, and the reported failure was the last line. The step spent just over five minutes retrying inside Install-Module before giving up. PR #2603 is failing the same way. Two changes. Install-PinnedModule in build/Update-CommandReference.ps1 replaces the three bare Install-Module calls. It returns immediately when the pinned version is already present, retries a failed download three times with a growing pause, and throws naming the module, the version and the Gallery when it still cannot be had. Install-Module writes a non-terminating error on a failed download, so the old code carried on to the Import-Module calls and failed there instead, which is where the misleading message came from. The same helper also makes the script survivable when run by hand. The workflow caches ~/.local/share/powershell/Modules, keyed on the files that pin the versions, so on a hit the Gallery is not contacted at all. The job already caches the Open Graph cards this way, with the same pinned actions/cache. Its own Install-Module for Microsoft.Graph.Authentication gets the same retry, inline. Verified locally: the three paths of Install-PinnedModule (already present, transient failure that then succeeds, and permanent failure) with the install and availability checks stubbed; the YAML parses and the cache step is ordered before both installs; the embedded PowerShell parses; the cached path is the CurrentUser module path on Linux; and PSScriptAnalyzer reports no Error or Warning on the changed script, which is what main reports for it today. What I could not verify locally is the cache hit itself, since that needs the Actions cache. --- .github/workflows/build-website.yaml | 29 ++++++++++++++++++-- build/Update-CommandReference.ps1 | 41 ++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-website.yaml b/.github/workflows/build-website.yaml index d51cedc6f1..725f9ddeb9 100644 --- a/.github/workflows/build-website.yaml +++ b/.github/workflows/build-website.yaml @@ -93,10 +93,35 @@ jobs: - name: "\U0001F4E6 Install dependencies" run: npm ci - # The test catalog export imports the source module, which needs this module. + # The PowerShell modules the build needs, by the pinned versions in the files that pin them. On a hit the + # PowerShell Gallery is not contacted at all, which is the point: the Gallery handing a runner a source + # location it cannot use has failed this job with an error four steps removed from the cause. + - name: Restore the PowerShell modules + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.local/share/powershell/Modules + key: pwsh-modules-${{ runner.os }}-${{ hashFiles('build/Update-CommandReference.ps1', '.github/workflows/build-website.yaml') }} + restore-keys: pwsh-modules-${{ runner.os }}- + + # The test catalog export imports the source module, which needs this module. Retried, because a failed + # download here is a Gallery problem rather than a problem with the change being built. - name: Install Microsoft.Graph.Authentication shell: pwsh - run: Install-Module Microsoft.Graph.Authentication -MinimumVersion 2.27.0 -Scope CurrentUser -Repository PSGallery -Force + run: | + $ErrorActionPreference = 'Stop' + $available = { [bool](Get-Module Microsoft.Graph.Authentication -ListAvailable | + Where-Object { $_.Version -ge [version]'2.27.0' }) } + if (& $available) { 'Already available.'; exit 0 } + foreach ($attempt in 1..3) { + try { + Install-Module Microsoft.Graph.Authentication -MinimumVersion 2.27.0 -Scope CurrentUser -Repository PSGallery -Force + } catch { + Write-Host "::warning::Attempt $attempt of 3 failed: $($_.Exception.Message)" + } + if (& $available) { exit 0 } + if ($attempt -lt 3) { Start-Sleep -Seconds (5 * $attempt) } + } + throw 'Could not install Microsoft.Graph.Authentication from the PowerShell Gallery after 3 attempts.' # The Open Graph cards rendered by earlier builds, by their hash (scripts/og-images.mjs): a build renders only # the cards of the pages that changed. diff --git a/build/Update-CommandReference.ps1 b/build/Update-CommandReference.ps1 index c0f552d299..6ca144c1ab 100644 --- a/build/Update-CommandReference.ps1 +++ b/build/Update-CommandReference.ps1 @@ -6,9 +6,44 @@ $alt3DocusaurusVersion = "1.0.37" $platyPSVersion = "0.14.2" -if (-not (Get-Module Alt3.Docusaurus.Powershell -ListAvailable | Where-Object { $_.Version -eq $alt3DocusaurusVersion })) { Install-Module Alt3.Docusaurus.Powershell -RequiredVersion $alt3DocusaurusVersion -Scope CurrentUser -Force -SkipPublisherCheck } -if (-not (Get-Module PlatyPS -ListAvailable | Where-Object { $_.Version -eq $platyPSVersion })) { Install-Module PlatyPS -RequiredVersion $platyPSVersion -Scope CurrentUser -Force -SkipPublisherCheck } -if (-not (Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq '5.7.1' })) { Install-Module Pester -RequiredVersion 5.7.1 -Scope CurrentUser -Force -SkipPublisherCheck } +# Installs a pinned module, retrying a failed download, and stops with a message that names the +# cause when it cannot be had at all. +# +# Install-Module writes a non-terminating error on a failed download, so without this the script +# used to carry on to the Import-Module calls below and fail there instead, with +# "The specified module 'PlatyPS' with version '0.14.2' was not loaded because no valid module file +# was found", four steps away from the PowerShell Gallery handing the runner a source location it +# could not use. A Gallery hiccup then reads as a problem with the branch being built. +function Install-PinnedModule { + param( + [Parameter(Mandatory)] [string] $Name, + [Parameter(Mandatory)] [string] $Version, + [int] $Attempts = 3 + ) + + $isAvailable = { [bool](Get-Module $Name -ListAvailable | Where-Object { $_.Version -eq $Version }) } + if (& $isAvailable) { + Write-Verbose "$Name $Version is already available." + return + } + + for ($attempt = 1; $attempt -le $Attempts; $attempt++) { + try { + Install-Module $Name -RequiredVersion $Version -Scope CurrentUser -Force -SkipPublisherCheck -ErrorAction Stop + } catch { + Write-Warning "Attempt $attempt of $Attempts to install $Name $Version failed: $($_.Exception.Message)" + } + + if (& $isAvailable) { return } + if ($attempt -lt $Attempts) { Start-Sleep -Seconds (5 * $attempt) } + } + + throw "Could not install $Name $Version from the PowerShell Gallery after $Attempts attempts. The command reference cannot be generated without it." +} + +Install-PinnedModule -Name Alt3.Docusaurus.Powershell -Version $alt3DocusaurusVersion +Install-PinnedModule -Name PlatyPS -Version $platyPSVersion +Install-PinnedModule -Name Pester -Version '5.7.1' Import-Module Alt3.Docusaurus.Powershell -RequiredVersion $alt3DocusaurusVersion Import-Module PlatyPS -RequiredVersion $platyPSVersion From 33db843d62202df7b63096bb22ac36fe073ca4f8 Mon Sep 17 00:00:00 2001 From: Eduard Arbona Date: Fri, 6 Nov 2026 15:16:47 -0400 Subject: [PATCH 2/2] fix(tests): match the Pester pin guard to the retry-helper call form The guard asserted the literal 'Install-Module Pester -RequiredVersion 5.7.1' in build/Update-CommandReference.ps1. That install now goes through the retry helper, so the pin reads 'Install-PinnedModule -Name Pester -Version 5.7.1' and the guard failed on ubuntu while the version was still pinned. Updated the pattern the same way the repo already does for .github/workflows/build-validation.yaml, whose install also goes through a helper. Verified with a negative control: changing the file to 5.7.2 fails the guard, so it still catches an unpinned or bumped version. --- powershell/tests/general/PesterVersionPinning.Tests.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/powershell/tests/general/PesterVersionPinning.Tests.ps1 b/powershell/tests/general/PesterVersionPinning.Tests.ps1 index d48b74eb78..8739c55079 100644 --- a/powershell/tests/general/PesterVersionPinning.Tests.ps1 +++ b/powershell/tests/general/PesterVersionPinning.Tests.ps1 @@ -19,7 +19,8 @@ BeforeDiscovery { } @{ Path = 'build/Update-CommandReference.ps1' - Pattern = 'Install-Module Pester -RequiredVersion 5\.7\.1' + # Doc generation installs through a retry helper that takes the version as a parameter. + Pattern = "Install-PinnedModule -Name Pester -Version '5\.7\.1'" Because = 'doc generation should install the supported Pester version when missing' } @{