Skip to content

Commit 41f022c

Browse files
Fix publishing new Gallery versions
Co-authored-by: MariusStorhaug <17722253+MariusStorhaug@users.noreply.github.com>
1 parent 1ea1be8 commit 41f022c

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

.github/actions/Publish-PSModule/src/publish.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ LogGroup 'Publish to PSGallery' {
145145
if ($whatIf) {
146146
Write-Host "Publish-PSResource -Path $modulePath -Repository PSGallery -ApiKey ***"
147147
} else {
148-
$publishedPackage = Find-PSResource -Name $name -Version $publishPSVersion -Repository PSGallery -ErrorAction Stop
148+
$publishedPackage = Find-PSResource -Name $name -Version $publishPSVersion -Repository PSGallery -ErrorAction SilentlyContinue
149149
if ($publishedPackage) {
150150
Write-Host (
151151
"::notice title=♻️ Resuming Gallery-only publication::$name $publishPSVersion is already " +

.github/actions/Publish-PSModule/tests/Publish-PSModule.Recovery.Tests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,25 @@ Describe 'Publish-PSModule recovery' {
8484

8585
$script:publishInvoked | Should -BeFalse
8686
}
87+
88+
It 'publishes when the resolved version is not in the Gallery' {
89+
$publishMarkerPath = Join-Path -Path $script:workspacePath -ChildPath 'publish-invoked'
90+
Set-Item -Path function:global:Find-PSResource -Value {
91+
[CmdletBinding()]
92+
param(
93+
[string] $Name,
94+
[string] $Version,
95+
[string] $Repository
96+
)
97+
98+
Write-Error "Package with name '$Name', version '$Version' could not be found in repository '$Repository'."
99+
}
100+
Set-Item -Path function:global:Publish-PSResource -Value {
101+
$null = New-Item -Path (Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'publish-invoked') -ItemType File -Force
102+
}
103+
104+
{ & $script:publishScriptPath } | Should -Not -Throw
105+
106+
(Test-Path -Path $publishMarkerPath) | Should -BeTrue
107+
}
87108
}

0 commit comments

Comments
 (0)