Skip to content

Commit 818d5cc

Browse files
committed
fix(Publish-PSModule): 🐛 Fix failure when there's a delay in publishing the module
1 parent c1dc410 commit 818d5cc

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

build.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
$BuildPSModule = @{
22
Name = 'PSModuleUtils'
3-
Version = '1.7.0-preview1'
3+
Version = '1.7.0-preview2'
44
Description = 'A module with helper functions to build and publish PowerShell modules to the PSGallery.'
55
Tags = ('PSEdition_Desktop', 'PSEdition_Core', 'Windows')
66
}

src/public/Publish-PSModule.ps1

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,30 @@ function Publish-PSModule {
4242
-ApiKey $ApiKey `
4343
-Repository $Repository
4444

45-
Find-PSResource `
46-
-Name $Name `
47-
-Version $versionedFolder.BaseName `
48-
-Prerelease `
49-
-Repository $Repository
45+
$maxRetries = 5
46+
$attempt = 0
47+
$delayIntervals = 1, 2, 3, 5, 8
48+
do {
49+
try {
50+
$publishedModule = Find-PSResource `
51+
-Name $Name `
52+
-Version $versionedFolder.BaseName `
53+
-Prerelease `
54+
-Repository $Repository
55+
break
56+
}
57+
catch {
58+
Write-Verbose -Message (
59+
"Couldn't find published module. Retrying after $($delayInterval[$attempt]) seconds."
60+
)
61+
Start-Sleep -Seconds $delayIntervals[$attempt]
62+
$attempt++
63+
if ($attempt -ge $maxRetries) {
64+
throw $_
65+
}
66+
}
67+
}
68+
while (-not $publishedModule -and $attempt -lt $maxRetries)
5069
}
5170
else {
5271
Write-Warning -Message "No module named $Name found to publish."

0 commit comments

Comments
 (0)