Skip to content

Commit 8fa2f24

Browse files
tablackburnclaude
andauthored
ci(release): allow PSGallery publish to recover when the GitHub release already exists (#20)
* ci(release): allow PSGallery publish to recover when the release already exists Propagates PowerShellModuleTemplate#33. Publishing was gated on 'GitHub release does not exist', so a release-created-but-publish-failed run could never recover. Regate: PSGallery check runs unconditionally; Bootstrap runs if a release or a publish is needed; Publish is gated only on the PSGallery check; Create Release unchanged. Flagged by CodeRabbit + Copilot during the YTMP rollout. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * ci(release): fail the PSGallery check on a query error instead of assuming not-published Addresses #20 review (Copilot): now that Publish is gated only on this check, Find-Module -ErrorAction SilentlyContinue returning $null was treated as 'not on gallery' for BOTH a genuine miss and a transient query failure. Capture -ErrorVariable: publish only on a clean miss (Find-Module records no error for a genuine not-found, verified); on a recorded error, throw so the run is retryable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e651a28 commit 8fa2f24

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

.github/workflows/PublishModuleToPowerShellGallery.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,31 @@ jobs:
4747
4848
- name: Check if PSGallery Version Exists
4949
id: check_psgallery
50-
if: steps.check_release.outputs.exists == 'false'
50+
# Runs unconditionally so a release that was created but never published can
51+
# still be recovered (see Publish gating below).
5152
shell: pwsh
5253
env:
5354
VERSION: ${{ steps.version.outputs.version }}
5455
run: |
5556
$version = $env:VERSION
56-
$published = Find-Module -Name ReScenePS -RequiredVersion $version -Repository PSGallery -ErrorAction SilentlyContinue
57+
$findError = $null
58+
$published = Find-Module -Name ReScenePS -RequiredVersion $version -Repository PSGallery -ErrorAction SilentlyContinue -ErrorVariable findError
5759
if ($published) {
5860
Write-Host "PSGallery version $version already exists"
5961
"exists=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
62+
} elseif ($findError) {
63+
# Find-Module records no error when the version simply isn't on the gallery,
64+
# so a recorded error means the query itself failed (transient/network). Don't
65+
# treat that as "not published" (publishing is now gated only on this check) —
66+
# fail so the run is visibly retryable instead of attempting a blind publish.
67+
throw "PowerShell Gallery query failed for version ${version}: $($findError[0].Exception.Message)"
6068
} else {
6169
Write-Host "PSGallery version $version not found - will publish"
6270
"exists=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
6371
}
6472
6573
- name: Bootstrap
66-
if: steps.check_release.outputs.exists == 'false'
74+
if: steps.check_release.outputs.exists == 'false' || steps.check_psgallery.outputs.exists == 'false'
6775
shell: pwsh
6876
run: ./build.ps1 -Task Init -Bootstrap
6977

@@ -124,7 +132,7 @@ jobs:
124132
}
125133
126134
- name: Publish to PSGallery
127-
if: steps.check_release.outputs.exists == 'false' && steps.check_psgallery.outputs.exists == 'false'
135+
if: steps.check_psgallery.outputs.exists == 'false'
128136
shell: pwsh
129137
env:
130138
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}

0 commit comments

Comments
 (0)