Skip to content

Commit a45cf36

Browse files
feat: improve powershell-yaml check (#502)
# Pull Request ## Description Improve the powershell-yaml check ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license.
1 parent 31dd46d commit a45cf36

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/ALZ/Private/Config-Helpers/Get-ALZConfig.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ function Get-ALZConfig {
2121
$extension = (Get-Item -Path $configFilePath).Extension.ToLower()
2222
$config = $null
2323
if ($extension -eq ".yml" -or $extension -eq ".yaml") {
24-
if (!(Get-Module -ListAvailable -Name powershell-Yaml)) {
25-
Write-Host "Installing YAML module"
26-
Install-Module powershell-Yaml -Force
27-
}
2824
try {
2925
$config = [PSCustomObject](Get-Content -Path $configFilePath | ConvertFrom-Yaml -Ordered)
3026
} catch {

src/ALZ/Private/Tools/Test-Tooling.ps1

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function Test-Tooling {
175175
if ($null -ne $alzModuleCurrentVersion) {
176176
if ($alzModuleCurrentVersion.Version -lt $alzModuleLatestVersion.Version) {
177177
$checkResults += @{
178-
message = "ALZ module is not the latest version. Your version: $($alzModuleCurrentVersion.Version), Latest version: $($alzModuleLatestVersion.Version). Please update to the latest version using 'Update-Module ALZ'."
178+
message = "ALZ module is not the latest version. Your version: $($alzModuleCurrentVersion.Version), Latest version: $($alzModuleLatestVersion.Version). Please update to the latest version using 'Update-PSResource -Name ALZ'."
179179
result = "Failure"
180180
}
181181
$hasFailure = $true
@@ -191,18 +191,32 @@ function Test-Tooling {
191191
# Check if powershell-yaml module is installed (only when YAML files are being used)
192192
if ($checkYamlModule.IsPresent) {
193193
Write-Verbose "Checking powershell-yaml module installation"
194-
$yamlModule = Get-Module -ListAvailable -Name powershell-yaml
194+
$yamlModule = Get-InstalledPSResource -Name powershell-yaml 2> $null
195195
if ($yamlModule) {
196196
$checkResults += @{
197197
message = "powershell-yaml module is installed (version $($yamlModule.Version))."
198198
result = "Success"
199199
}
200200
} else {
201-
$checkResults += @{
202-
message = "powershell-yaml module is not installed. Please install it using 'Install-Module powershell-yaml -Force'."
203-
result = "Failure"
201+
$installSuccessful = $false
202+
try {
203+
Install-PSResource powershell-yaml -TrustRepository
204+
$installSuccessful = $true
205+
} catch {
206+
Write-Verbose "Failed to install powershell-yaml module"
207+
}
208+
if($installSuccessful) {
209+
$checkResults += @{
210+
message = "powershell-yaml module was not installed, but has been successfully installed (version $((Get-InstalledPSResource -Name powershell-yaml).Version))."
211+
result = "Success"
212+
}
213+
} else {
214+
$checkResults += @{
215+
message = "powershell-yaml module is not installed. Please install it using 'Install-PSResource powershell-yaml'."
216+
result = "Failure"
217+
}
218+
$hasFailure = $true
204219
}
205-
$hasFailure = $true
206220
}
207221
}
208222

0 commit comments

Comments
 (0)