From 1f1c4d7872d237ced424e3818795ec740b7020fb Mon Sep 17 00:00:00 2001 From: Trent Blackburn Date: Thu, 21 May 2026 21:24:08 -0400 Subject: [PATCH] ci(release): fail the PSGallery check on a query error instead of assuming not-published Follow-up to recovery-gap #11. Publish is now gated only on this check, so a transient Find-Module failure (returning $null under -ErrorAction SilentlyContinue) was indistinguishable from a genuine miss and could trigger a blind publish. Capture -ErrorVariable: publish only on a clean miss (genuine not-found records no error, verified); throw on a recorded error so the run is retryable. 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 041f8bc..ae92024 100644 --- a/.github/workflows/PublishModuleToPowerShellGallery.yaml +++ b/.github/workflows/PublishModuleToPowerShellGallery.yaml @@ -76,10 +76,17 @@ jobs: VERSION: ${{ steps.version.outputs.version }} run: | $version = $env:VERSION - $published = Find-Module -Name JsmOperations -RequiredVersion $version -Repository PSGallery -ErrorAction SilentlyContinue + $findError = $null + $published = Find-Module -Name JsmOperations -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