Skip to content

Commit a5924a9

Browse files
committed
Add validation for required dependencies in build script.
1 parent 4ba4d02 commit a5924a9

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

.build.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ if ($PushToGallery -and ($Tasks -notcontains 'Release')) {
4141
if ($PSVersionTable.PSVersion -lt [Version]'7.4') {
4242
throw "This build requires PowerShell 7.4+. Current: $($PSVersionTable.PSVersion). Use 'pwsh' and retry."
4343
}
44+
# Required dependencies validation (fail fast).
45+
'Microsoft.PowerShell.PSResourceGet', 'InvokeBuild', 'Pester', 'PSScriptAnalyzer', 'Microsoft.PowerShell.PlatyPS' | ForEach-Object {
46+
if (-not (Get-Module -ListAvailable -Name $_ -ErrorAction SilentlyContinue)) {
47+
$installCommand = $_ -eq 'Microsoft.PowerShell.PSResourceGet' ? "Install-Module $_" : "Install-PSResource $_"
48+
throw @"
49+
${_} is required.
50+
51+
Install then retry(sample command is CurrentUser scope to avoid requiring admin privileges):
52+
$installCommand
53+
"@
54+
}
55+
}
4456
# --- Setup ---
4557

4658
Set-StrictMode -Version Latest

0 commit comments

Comments
 (0)