Fix ARM-ttk issue #6
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Unit Test ARM templates with arm-ttk | |
########################################## | |
# Start the job on PR for all branches # | |
######################################### | |
# yamllint disable-line rule:truthy | |
on: | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- ready_for_review | |
paths: | |
- "services/**/**/templates/arm/**.json" | |
workflow_dispatch: { } | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
validate-arm-files: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{github.event.pull_request.head.ref}} | |
repository: ${{github.event.pull_request.head.repo.full_name}} | |
- name: Clone ARM-TTK repo | |
uses: GuillaumeFalourd/clone-github-repo-action@v3 | |
with: | |
owner: 'Azure' | |
repository: 'arm-ttk' | |
- name: Test Modified ARM templates | |
id: run_tests | |
shell: pwsh | |
run: | | |
$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 | |
} |