diff --git a/.github/workflows/unit-test-arm-templates.yml b/.github/workflows/unit-test-arm-templates.yml index 83a4d1f2e..2d973821f 100644 --- a/.github/workflows/unit-test-arm-templates.yml +++ b/.github/workflows/unit-test-arm-templates.yml @@ -31,6 +31,20 @@ jobs: fetch-depth: 0 ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} + - name: Get all changed ARM files + id: changed-arm-files + uses: tj-actions/changed-files@v45 + with: + files: | + services/**/**/templates/arm/**.json + - name: List all changed ARM files + if: steps.changed-arm-files.outputs.any_changed == 'true' + env: + ALL_CHANGED_FILES: ${{ steps.changed-arm-files.outputs.all_changed_files }} + run: | + for file in ${ALL_CHANGED_FILES}; do + echo "File changed: $file" + done - name: Clone ARM-TTK repo uses: GuillaumeFalourd/clone-github-repo-action@v3 with: @@ -38,31 +52,30 @@ jobs: repository: 'arm-ttk' - name: Test Modified ARM templates id: run_tests + if: steps.changed-arm-files.outputs.any_changed == 'true' shell: pwsh run: | - $changedFiles = git diff --name-only 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++ - } - } - } - } - } + $changedFiles = "${{ steps.changed-arm-files.outputs.all_changed_files }}" + $changedFiles = $changedFiles -split ' ' + # Initialize a counter for the number of failed tests + $NumberOfFailedTests = 0 + If ($changedFiles -ne $null) { + Import-Module ./arm-ttk/arm-ttk/arm-ttk.psd1 + $changedFiles | 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