Support az bicep build in New-TestResources (#6572)

Co-authored-by: Patrick Hallisey <pahallis@microsoft.com>
This commit is contained in:
Azure SDK Bot 2025-05-14 17:38:51 -07:00 committed by GitHub
parent c61528188c
commit 77eee12717
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -129,8 +129,30 @@ function MergeHashes([hashtable] $source, [psvariable] $dest) {
}
}
function IsBicepInstalled() {
try {
bicep --version | Out-Null
return $LASTEXITCODE -eq 0
}
catch {
return $false
}
}
function IsAzCliBicepInstalled() {
try {
az bicep version | Out-Null
return $LASTEXITCODE -eq 0
}
catch {
return $false
}
}
function BuildBicepFile([System.IO.FileSystemInfo] $file) {
if (!(Get-Command bicep -ErrorAction Ignore)) {
$useBicepCli = IsBicepInstalled
if (!$useBicepCli -and !(IsAzCliBicepInstalled)) {
Write-Error "A bicep file was found at '$($file.FullName)' but the Azure Bicep CLI is not installed. See https://aka.ms/bicep-install"
throw
}
@ -140,7 +162,12 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file) {
# Az can deploy bicep files natively, but by compiling here it becomes easier to parse the
# outputted json for mismatched parameter declarations.
bicep build $file.FullName --outfile $templateFilePath
if ($useBicepCli) {
bicep build $file.FullName --outfile $templateFilePath
} else {
az bicep build --file $file.FullName --outfile $templateFilePath
}
if ($LASTEXITCODE) {
Write-Error "Failure building bicep file '$($file.FullName)'"
throw
@ -150,13 +177,22 @@ function BuildBicepFile([System.IO.FileSystemInfo] $file) {
}
function LintBicepFile([string] $path) {
if (!(Get-Command bicep -ErrorAction Ignore)) {
Write-Error "A bicep file was found at '$path' but the Azure Bicep CLI is not installed. See https://aka.ms/bicep-install"
throw
$useBicepCli = IsBicepInstalled
if (!$useBicepCli -and !(IsAzCliBicepInstalled)) {
Write-Error "A bicep file was found at '$path' but the Azure Bicep CLI is not installed. See https://aka.ms/bicep-install"
throw
}
# Work around lack of config file override: https://github.com/Azure/bicep/issues/5013
$output = bicep lint "$path" 2>&1
$output = bicep lint $path 2>&1
if ($useBicepCli) {
$output = bicep lint $path 2>&1
} else {
$output = az bicep lint --file $path 2>&1
}
if ($LASTEXITCODE) {
Write-Error "Failed linting bicep file '$path'"
throw