Skip to content

Commit 74ea471

Browse files
Remove obsolete module requirements and refactor retry logic in Publish-PSModule function
1 parent d464c20 commit 74ea471

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

scripts/Helpers/Helpers.psm1

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ function Build-PSModule {
7575
#>
7676
[OutputType([void])]
7777
[CmdletBinding()]
78-
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
79-
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
8078
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
8179
'PSReviewUnusedParameter', '', Scope = 'Function',
8280
Justification = 'LogGroup - Scoping affects the variables line of sight.'
@@ -132,7 +130,6 @@ function Build-PSModuleBase {
132130
Build-PSModuleBase -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule'
133131
#>
134132
[CmdletBinding()]
135-
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
136133
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
137134
'PSReviewUnusedParameter', '', Scope = 'Function',
138135
Justification = 'LogGroup - Scoping affects the variables line of sight.'
@@ -309,8 +306,7 @@ function Build-PSModuleManifest {
309306
Build-PSModuleManifest -SourceFolderPath 'C:\MyModule\src\MyModule' -OutputFolderPath 'C:\MyModule\build\MyModule'
310307
#>
311308
[CmdletBinding()]
312-
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
313-
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
309+
314310
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
315311
'PSAvoidLongLines', '', Scope = 'Function',
316312
Justification = 'Easier to read the multi ternery operators in a single line.'
@@ -762,9 +758,6 @@ function Build-PSModuleManifest {
762758
}
763759
}
764760

765-
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
766-
#Requires -Modules @{ ModuleName = 'Hashtable'; ModuleVersion = '1.1.1' }
767-
768761
function Build-PSModuleRootModule {
769762
<#
770763
.SYNOPSIS
@@ -1141,7 +1134,6 @@ function Get-PSModuleAliasesToExport {
11411134
Get-PSModuleAliasesToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
11421135
#>
11431136
[CmdletBinding()]
1144-
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
11451137
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
11461138
'PSAvoidUsingWriteHost', '', Scope = 'Function',
11471139
Justification = 'Want to just write to the console, not the pipeline.'
@@ -1222,7 +1214,6 @@ function Get-PSModuleCmdletsToExport {
12221214
Get-PSModuleCmdletsToExport -SourceFolderPath 'C:\MyModule\src\MyModule'
12231215
#>
12241216
[CmdletBinding()]
1225-
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
12261217
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
12271218
'PSAvoidUsingWriteHost', '', Scope = 'Function',
12281219
Justification = 'Want to just write to the console, not the pipeline.'
@@ -1434,7 +1425,6 @@ function Publish-PSModule {
14341425
#>
14351426
[OutputType([void])]
14361427
[CmdletBinding()]
1437-
#Requires -Modules Utilities, PowerShellGet, Microsoft.PowerShell.PSResourceGet, Retry, GitHub, PSSemVer
14381428
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
14391429
'PSReviewUnusedParameter', '', Scope = 'Function',
14401430
Justification = 'LogGroup - Scoping affects the variables line of sight.'
@@ -1613,12 +1603,21 @@ function Publish-PSModule {
16131603

16141604
LogGroup 'Get latest version - PSGallery' {
16151605
try {
1616-
Retry -Count 5 -Delay 10 {
1617-
Write-Output "Finding module [$Name] in the PowerShell Gallery."
1618-
$latest = Find-PSResource -Name $Name -Repository PSGallery -Verbose:$false
1619-
Write-Output ($latest | Format-Table | Out-String)
1620-
} -Catch {
1621-
throw $_
1606+
$retryCount = 5
1607+
$retryDelay = 10
1608+
for ($i = 0; $i -lt $retryCount; $i++) {
1609+
try {
1610+
Write-Output "Finding module [$Name] in the PowerShell Gallery."
1611+
$latest = Find-PSResource -Name $Name -Repository PSGallery -Verbose:$false
1612+
Write-Output ($latest | Format-Table | Out-String)
1613+
break
1614+
} catch {
1615+
if ($i -eq $retryCount - 1) {
1616+
throw $_
1617+
}
1618+
Write-Warning "Retrying in $retryDelay seconds..."
1619+
Start-Sleep -Seconds $retryDelay
1620+
}
16221621
}
16231622
$psGalleryVersion = New-PSSemVer -Version $latest.Version
16241623
} catch {
@@ -2015,8 +2014,6 @@ function Update-PSModuleManifestAliasesToExport {
20152014
'PSAvoidUsingWriteHost', '', Scope = 'Function',
20162015
Justification = 'Want to just write to the console, not the pipeline.'
20172016
)]
2018-
#Requires -Modules @{ ModuleName = 'GitHub'; ModuleVersion = '0.13.2' }
2019-
#Requires -Modules @{ ModuleName = 'Utilities'; ModuleVersion = '0.3.0' }
20202017
[CmdletBinding()]
20212018
param(
20222019
# Name of the module.

0 commit comments

Comments
 (0)