Skip to content

Commit 9edab5d

Browse files
🩹 [Patch]: Improve module installation logic (#78)
## Description This pull request includes updates to the `scripts/main.ps1` file to improve the installation and logging process for PowerShell modules. Logging improvements: * Added a log message before attempting to install each module to provide better visibility into the installation process. * Enhanced error messages to include the module name, making it easier to identify which module's installation failed. * Added a retry log message to indicate when the script is waiting before retrying the installation. Installation process improvements: * Changed the `Install-PSResource` command to use `WarningAction SilentlyContinue` and specify the repository as `PSGallery` to handle warnings more gracefully and ensure the correct repository is used. * Added a command to import each module after installation to ensure the modules are available for use immediately. ## 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 15e5c40 commit 9edab5d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

scripts/main.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@ param()
1111
LogGroup 'Loading libraries' {
1212
'powershell-yaml', 'PSSemVer' | ForEach-Object {
1313
$name = $_
14+
Write-Output "Installing module: $name"
1415
$count = 5
1516
$delay = 10
1617
for ($i = 1; $i -le $count; $i++) {
1718
try {
18-
Install-PSResource -Name $name -TrustRepository -ErrorAction Stop
19+
Install-PSResource -Name $name -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery
1920
break
2021
} catch {
21-
Write-Warning $_.Exception.Message
22+
Write-Warning "Installation of $name failed with error: $_"
2223
if ($i -eq $count) {
2324
throw $_
2425
}
26+
Write-Warning "Retrying in $delay seconds..."
2527
Start-Sleep -Seconds $delay
2628
}
2729
}
30+
Import-Module -Name $name
2831
}
2932
}
3033

0 commit comments

Comments
 (0)