Skip to content

Commit e2c6e91

Browse files
🩹 [Patch]: Add retry on Install-PSResource (#12)
## Description This pull request includes changes to the `.github/workflows/Action-Test.yml` file to improve the reliability of module installation by adding retry logic. Improvements to module installation: * [`.github/workflows/Action-Test.yml`](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L141-R160): Added a retry mechanism for the `Install-PSResource` command to handle potential installation failures more gracefully. This includes retrying the installation up to 5 times with a 10-second delay between attempts and logging appropriate messages. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent a2c4cfb commit e2c6e91

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

.github/workflows/Action-Test.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,26 @@ jobs:
138138
uses: PSModule/Github-Script@v1
139139
with:
140140
Script: |
141-
Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository
141+
'Markdown' | ForEach-Object {
142+
$name = $_
143+
Write-Output "Installing module: $name"
144+
$retryCount = 5
145+
$retryDelay = 10
146+
for ($i = 0; $i -lt $retryCount; $i++) {
147+
try {
148+
Install-PSResource -Name $name -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery
149+
break
150+
} catch {
151+
Write-Warning "Installation of $name failed with error: $_"
152+
if ($i -eq $retryCount - 1) {
153+
throw
154+
}
155+
Write-Warning "Retrying in $retryDelay seconds..."
156+
Start-Sleep -Seconds $retryDelay
157+
}
158+
}
159+
Import-Module -Name $name
160+
}
142161
143162
# Build an array of objects for each job
144163
$ActionTestSrcSourceCodeExpectedOutcome = 'success'

0 commit comments

Comments
 (0)