From 282de8afe1bfcbaf84caa566b7de35543c787707 Mon Sep 17 00:00:00 2001 From: Trent Blackburn Date: Thu, 21 May 2026 21:23:15 -0400 Subject: [PATCH] ci(release): fail the PSGallery check on a query error instead of assuming not-published MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that Publish is gated only on this check (recovery-gap fix #33), a Find-Module -ErrorAction SilentlyContinue returning $null was treated as 'not on gallery' for BOTH a genuine miss and a transient query failure — so a network/PSGallery hiccup could trigger a blind publish attempt. Capture -ErrorVariable: publish only on a clean miss (Find-Module records no error for a genuine not-found, verified for new-version and never-published cases); on a recorded error, throw so the run is visibly retryable. Surfaced by CodeRabbit/Copilot during the YouTubeMusicPS rollout review. Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/PublishModuleToPowerShellGallery.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/PublishModuleToPowerShellGallery.yaml b/.github/workflows/PublishModuleToPowerShellGallery.yaml index 9e83099..20547cd 100644 --- a/.github/workflows/PublishModuleToPowerShellGallery.yaml +++ b/.github/workflows/PublishModuleToPowerShellGallery.yaml @@ -74,10 +74,17 @@ jobs: VERSION: ${{ steps.version.outputs.version }} run: | $version = $env:VERSION - $published = Find-Module -Name {{ModuleName}} -RequiredVersion $version -Repository PSGallery -ErrorAction SilentlyContinue + $findError = $null + $published = Find-Module -Name {{ModuleName}} -RequiredVersion $version -Repository PSGallery -ErrorAction SilentlyContinue -ErrorVariable findError if ($published) { Write-Host "PSGallery version $version already exists" "exists=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append + } elseif ($findError) { + # Find-Module records no error when the version simply isn't on the gallery, + # so a recorded error means the query itself failed (transient/network). Don't + # treat that as "not published" (publishing is now gated only on this check) — + # fail so the run is visibly retryable instead of attempting a blind publish. + throw "PowerShell Gallery query failed for version ${version}: $($findError[0].Exception.Message)" } else { Write-Host "PSGallery version $version not found - will publish" "exists=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append