Update test result processing to use NUnitXml format and enhance logging for better clarity (#25288)

This commit is contained in:
Travis Plunk
2025-04-07 20:24:09 +00:00
committed by GitHub
parent 8562f9e813
commit 71e9532557
5 changed files with 125 additions and 59 deletions
+1 -1
View File
@@ -101,7 +101,7 @@ runs:
chmod a+x $pwshPath
$options.Output = $pwshPath
Set-PSOptions $options
Invoke-CITest -Purpose '${{ inputs.purpose }}' -TagSet '${{ inputs.tagSet }}' -TitlePrefix '${{ inputs.buildName }}' -OutputFormat JUnitXml
Invoke-CITest -Purpose '${{ inputs.purpose }}' -TagSet '${{ inputs.tagSet }}' -TitlePrefix '${{ inputs.buildName }}' -OutputFormat NUnitXml
shell: pwsh
- name: Convert, Publish, and Upload Pester Test Results
@@ -10,46 +10,13 @@ inputs:
required: false
default: "${{ runner.workspace }}/testResults"
type: string
ctrfFolder:
required: false
default: ctrf
type: string
runs:
using: composite
steps:
- name: Log Summary
run: |
if (-not $env:GITHUB_STEP_SUMMARY) {
Write-Error "GITHUB_STEP_SUMMARY is not set. Ensure this workflow is running in a GitHub Actions environment."
exit 1
}
$testCaseCount = 0
$testErrorCount = 0
$testFailureCount = 0
$testDisabledCount = 0
Get-ChildItem -Path "${{ inputs.testResultsFolder }}/*.xml" -Recurse | ForEach-Object {
$results = [xml] (get-content $_.FullName)
$testCaseCount += $results.testsuites.tests
$testErrorCount += $results.testsuites.errors
$testFailureCount += $results.testsuites.failures
$testDisabledCount += $results.testsuites.disabled
}
@"
# Summary of ${{ inputs.name }}
- Total Tests: $testCaseCount
- Total Errors: $testErrorCount
- Total Failures: $testFailureCount
- Total Disabled: $testDisabledCount
"@ | Out-File -FilePath $ENV:GITHUB_STEP_SUMMARY -Append
Write-Host "Summary written to $ENV:GITHUB_STEP_SUMMARY"
Get-Content $ENV:GITHUB_STEP_SUMMARY
run: |-
& "$env:GITHUB_ACTION_PATH/process-pester-results.ps1" -Name '${{ inputs.name }}' -TestResultsFolder '${{ inputs.testResultsFolder }}'
shell: pwsh
- name: Upload testResults artifact
@@ -0,0 +1,68 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
param(
[parameter(Mandatory)]
[string]$Name,
[parameter(Mandatory)]
[string]$TestResultsFolder
)
Import-Module "$PSScriptRoot/../../../../build.psm1"
if (-not $env:GITHUB_STEP_SUMMARY) {
Write-Error "GITHUB_STEP_SUMMARY is not set. Ensure this workflow is running in a GitHub Actions environment."
exit 1
}
$testCaseCount = 0
$testErrorCount = 0
$testFailureCount = 0
$testNotRunCount = 0
$testInconclusiveCount = 0
$testIgnoredCount = 0
$testSkippedCount = 0
$testInvalidCount = 0
Get-ChildItem -Path "${TestResultsFolder}/*.xml" -Recurse | ForEach-Object {
$results = [xml] (get-content $_.FullName)
$testCaseCount += [int]$results.'test-results'.total
$testErrorCount += [int]$results.'test-results'.errors
$testFailureCount += [int]$results.'test-results'.failures
$testNotRunCount += [int]$results.'test-results'.'not-run'
$testInconclusiveCount += [int]$results.'test-results'.inconclusive
$testIgnoredCount += [int]$results.'test-results'.ignored
$testSkippedCount += [int]$results.'test-results'.skipped
$testInvalidCount += [int]$results.'test-results'.invalid
}
@"
# Summary of $Name
- Total Tests: $testCaseCount
- Total Errors: $testErrorCount
- Total Failures: $testFailureCount
- Total Not Run: $testNotRunCount
- Total Inconclusive: $testInconclusiveCount
- Total Ignored: $testIgnoredCount
- Total Skipped: $testSkippedCount
- Total Invalid: $testInvalidCount
"@ | Out-File -FilePath $ENV:GITHUB_STEP_SUMMARY -Append
Write-Log "Summary written to $ENV:GITHUB_STEP_SUMMARY"
Write-LogGroupStart -Title 'Test Results'
Get-Content $ENV:GITHUB_STEP_SUMMARY
Write-LogGroupEnd -Title 'Test Results'
if ($testErrorCount -gt 0 -or $testFailureCount -gt 0) {
Write-Error "There were $testErrorCount/$testFailureCount errors/failures in the test results."
exit 1
}
if ($testCaseCount -eq 0) {
Write-Error "No test cases were run."
exit 1
}
+16 -4
View File
@@ -20,15 +20,25 @@ runs:
steps:
- name: Capture Environment
if: success() || failure()
run: 'Get-ChildItem -Path env: | Out-String -width 9999 -Stream | write-Verbose -Verbose'
run: |-
Import-Module ./build.psm1
Write-LogGroupStart -Title 'Environment'
Get-ChildItem -Path env: | Out-String -width 9999 -Stream | write-Verbose -Verbose
Write-LogGroupEnd -Title 'Environment'
shell: pwsh
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
path: "${{ github.workspace }}"
- name: Capture Artifacts Directory
continue-on-error: true
run: Get-ChildItem "${{ github.workspace }}\build\*" -Recurse
run: |-
Import-Module ./build.psm1
Write-LogGroupStart -Title 'Artifacts Directory'
Get-ChildItem "${{ github.workspace }}/build/*" -Recurse
Write-LogGroupEnd -Title 'Artifacts Directory'
shell: pwsh
- uses: actions/setup-dotnet@v4
@@ -38,7 +48,8 @@ runs:
- name: Bootstrap
shell: powershell
run: |-
# Remove "Program Files\dotnet" from the env variable PATH, so old SDKs won't affect us.
Import-Module ./build.psm1
Write-LogGroupStart -Title 'Bootstrap'
Write-Host "Old Path:"
Write-Host $env:Path
$dotnetPath = Join-Path $env:SystemDrive 'Program Files\dotnet'
@@ -49,6 +60,7 @@ runs:
# Bootstrap
Import-Module .\tools\ci.psm1
Invoke-CIInstall
Write-LogGroupEnd -Title 'Bootstrap'
- name: Test
if: success()
@@ -60,7 +72,7 @@ runs:
$path = split-path -path $options.Output
$rootPath = split-Path -path $path
Expand-Archive -Path '${{ github.workspace }}\build\build.zip' -DestinationPath $rootPath -Force
Invoke-CITest -Purpose '${{ inputs.purpose }}' -TagSet '${{ inputs.tagSet }}' -OutputFormat JUnitXml
Invoke-CITest -Purpose '${{ inputs.purpose }}' -TagSet '${{ inputs.tagSet }}' -OutputFormat NUnitXml
shell: pwsh
- name: Convert, Publish, and Upload Pester Test Results