From e5e726fc48c66ac27973d30c98fd78c239e2f5ce Mon Sep 17 00:00:00 2001 From: Jan Faurskov <22591930+jfaurskov@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:02:02 +0200 Subject: [PATCH] Remove dependency on script --- .github/workflows/unit-test-arm-templates.yml | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-test-arm-templates.yml b/.github/workflows/unit-test-arm-templates.yml index 1a59510c6..7d31b198a 100644 --- a/.github/workflows/unit-test-arm-templates.yml +++ b/.github/workflows/unit-test-arm-templates.yml @@ -37,7 +37,41 @@ jobs: owner: 'Azure' repository: 'arm-ttk' - name: Test Modified ARM templates + id: run_tests shell: pwsh run: | - Import-Module ./arm-ttk/arm-ttk/arm-ttk.psd1 - ./.github/actions-pester/Test-ArmTemplates.Tests.ps1 + $changedFiles = git diff --name-only origin/main origin/${{github.event.pull_request.head.ref}} + # Initialize a counter for the number of failed tests + $NumberOfFailedTests = 0 + If ($changedFiles -ne $null) { + $armFiles = $changedFiles | where-object {$PSItem -match "services/.*/templates/arm/.*.json"} + If ($armFiles -ne $null) { + Import-Module ./arm-ttk/arm-ttk/arm-ttk.psd1 + $armFiles | ForEach-Object { + $armFile = $PSItem + write-output "Testing $armFile" + Test-AzTemplate -TemplatePath $armFile -Test deploymentTemplate -ErrorAction Continue + $testResults = Test-AzTemplate -TemplatePath $armFile -Test deploymentTemplate -ErrorAction Continue + # Filter the test results to find any failed tests + $failedTests = $testResults | Where-Object { $PSItem.Passed -ne $True } + # If there are failed tests, increment the failed tests counter + if ($failedTests -ne $null) { + $failedTests | ForEach-Object { + $NumberOfFailedTests++ + } + } + } + } + } + echo "failtests=$NumberOfFailedTests" + Add-Content -Path $env:GITHUB_ENV -Value "failtests=$NumberOfFailedTests" + continue-on-error: true + - name: Check for failed tests + id: check_fail + shell: pwsh + run: | + echo "Number of failed tests: ${{ env.failtests }}" + If (${{ env.failtests }} -gt 0) { + echo "Failed tests found, see previous step for details" + exit 1 + }