8000 Update test result processing to use NUnitXml format and enhance logg… · pwshBot/PowerShell@edadefb · GitHub
[go: up one dir, main page]

Skip to content

Commit edadefb

Browse files
TravisEz13pwshBot
authored andcommitted
Update test result processing to use NUnitXml format and enhance logging for better clarity (PowerShell#25288)
1 parent 27d1932 commit edadefb

File tree

5 files changed

+125
-59
lines changed

5 files changed

+125
-59
lines changed

.github/actions/test/nix/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ runs:
101101
chmod a+x $pwshPath
102102
$options.Output = $pwshPath
103103
Set-PSOptions $options
104-
Invoke-CITest -Purpose '${{ inputs.purpose }}' -TagSet '${{ inputs.tagSet }}' -TitlePrefix '${{ inputs.buildName }}' -OutputFormat JUnitXml
104+
Invoke-CITest -Purpose '${{ inputs.purpose }}' -TagSet '${{ inputs.tagSet }}' -TitlePrefix '${{ inputs.buildName }}' -OutputFormat NUnitXml
105105
shell: pwsh
106106

107107
- name: Convert, Publish, and Upload Pester Test Results

.github/actions/test/process-pester-results/action.yml

+2-35
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,13 @@ inputs:
1010
required: false
1111
default: "${{ runner.workspace }}/testResults"
1212
type: string
13-
ctrfFolder:
14-
required: false
15-
default: ctrf
16-
type: string
1713

1814
runs:
1915
using: composite
2016
steps:
2117
- name: Log Summary
22-
run: |
23-
if (-not $env:GITHUB_STEP_SUMMARY) {
24-
Write-Error "GITHUB_STEP_SUMMARY is not set. Ensure this workflow is running in a GitHub Actions environment."
25-
exit 1
26-
}
27-
28-
$testCaseCount = 0
29-
$testErrorCount = 0
30-
$testFailureCount = 0
31-
$testDisabledCount = 0
32-
Get-ChildItem -Path "${{ inputs.testResultsFolder }}/*.xml" -Recurse | ForEach-Object {
33-
$results = [xml] (get-content $_.FullName)
34-
$testCaseCount += $results.testsuites.tests
35-
$testErrorCount += $results.testsuites.errors
36-
$testFailureCount += $results.testsuites.failures
37-
$testDisabledCount += $results.testsuites.disabled
38-
}
39-
40-
@"
41-
42-
# Summary of ${{ inputs.name }}
43-
44-
- Total Tests: $testCaseCount
45-
- Total Errors: $testErrorCount
46-
- Total Failures: $testFailureCount
47-
- Total Disabled: $testDisabledCount
48-
49-
"@ | Out-File -FilePath $ENV:GITHUB_STEP_SUMMARY -Append
50-
51-
Write-Host "Summary written to $ENV:GITHUB_STEP_SUMMARY"
52-
Get-Content $ENV:GITHUB_STEP_SUMMARY
18+
run: |-
19+
& "$env:GITHUB_ACTION_PATH/process-pester-results.ps1" -Name '${{ inputs.name }}' -TestResultsFolder '${{ inputs.testResultsFolder }}'
5320
shell: pwsh
5421

5522
- name: Upload testResults artifact
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
param(
5+
[parameter(Mandatory)]
6+
[string]$Name,
7+
[parameter(Mandatory)]
8+
[string]$TestResultsFolder
9+
)
10+
11+
Import-Module "$PSScriptRoot/../../../../build.psm1"
12+
13+
if (-not $env:GITHUB_STEP_SUMMARY) {
14+
Write-Error "GITHUB_STEP_SUMMARY is not set. Ensure this workflow is running in a GitHub Actions environment."
15+
exit 1
16+
}
17+
18+
$testCaseCount = 0
19+
$testErrorCount = 0
20+
$testFailureCount = 0
21+
$testNotRunCount = 0
22+
$testInconclusiveCount = 0
23+
$testIgnoredCount = 0
24+
$testSkippedCount = 0
25+
$testInvalidCount = 0
26+
27+
Get-ChildItem -Path "${TestResultsFolder}/*.xml" -Recurse | ForEach-Object {
28+
$results = [xml] (get-content $_.FullName)
29+
30+
$testCaseCount += [int]$results.'test-results'.total
31+
$testErrorCount += [int]$results.'test-results'.errors
32+
$testFailureCount += [int]$results.'test-results'.failures
33+
$testNotRunCount += [int]$results.'test-results'.'not-run'
34+
$testInconclusiveCount += [int]$results.'test-results'.inconclusive
35+
$testIgnoredCount += [int]$results.'test-results'.ignored
36+
$testSkippedCount += [int]$results.'test-results'.skipped
37+
$testInvalidCount += [int]$results.'test-results'.invalid
38+
}
39+
40+
@"
41+
42+
# Summary of $Name
43+
44+
- Total Tests: $testCaseCount
45+
- Total Errors: $testErrorCount
46+
- Total Failures: $testFailureCount
47+
- Total Not Run: $testNotRunCount
48+
- Total Inconclusive: $testInconclusiveCount
49+
- Total Ignored: $testIgnoredCount
50+
- Total Skipped: $testSkippedCount
51+
- Total Invalid: $testInvalidCount
52+
53+
"@ | Out-File -FilePath $ENV:GITHUB_STEP_SUMMARY -Append
54+
55+
Write-Log "Summary written to $ENV:GITHUB_STEP_SUMMARY"
56+
57+
Write-LogGroupStart -Title 'Test Results'
58+
Get-Content $ENV:GITHUB_STEP_SUMMARY
59+
Write-LogGroupEnd -Title 'Test Results'
60+
61+
if ($testErrorCount -gt 0 -or $testFailureCount -gt 0) {
62+
Write-Error "There were $testErrorCount/$testFailureCount errors/failures in the test results."
63+
exit 1
64+
}
65+
if ($testCaseCount -eq 0) {
66+
Write-Error "No test cases were run."
67+
exit 1
68+
}

.github/actions/test/windows/action.yml

+16-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ runs:
2020
steps:
2121
- name: Capture Environment
2222
if: success() || failure()
23-
run: 'Get-ChildItem -Path env: | Out-String -width 9999 -Stream | write-Verbose -Verbose'
23+
run: |-
24+
Import-Module ./build.psm1
25+
Write-LogGroupStart -Title 'Environment'
26+
Get-ChildItem -Path env: | Out-String -width 9999 -Stream | write-Verbose -Verbose
27+
Write-LogGroupEnd -Title 'Environment'
2428
shell: pwsh
29+
2530
- name: Download Build Artifacts
2631
uses: actions/download-artifact@v4
2732
with:
2833
path: "${{ github.workspace }}"
34+
2935
- name: Capture Artifacts Directory
3036
continue-on-error: true
31-
run: Get-ChildItem "${{ github.workspace }}\build\*" -Recurse
37+
run: |-
38+
Import-Module ./build.psm1
39+
Write-LogGroupStart -Title 'Artifacts Directory'
40+
Get-ChildItem "${{ github.workspace }}/build/*" -Recurse
41+
Write-LogGroupEnd -Title 'Artifacts Directory'
3242
shell: pwsh
3343

3444
- uses: actions/setup-dotnet@v4
@@ -38,7 +48,8 @@ runs:
3848
- name: Bootstrap
3949
shell: powershell
4050
run: |-
41-
# Remove "Program Files\dotnet" from the env variable PATH, so old SDKs won't affect us.
51+
Import-Module ./build.psm1
52+
Write-LogGroupStart -Title 'Bootstrap'
4253
Write-Host "Old Path:"
4354
Write-Host $env:Path
4455
$dotnetPath = Join-Path $env:SystemDrive 'Program Files\dotnet'
@@ -49,6 +60,7 @@ runs:
4960
# Bootstrap
5061
Import-Module .\tools\ci.psm1
5162
Invoke-CIInstall
63+
Write-LogGroupEnd -Title 'Bootstrap'
5264
5365
- name: Test
5466
if: success()
@@ -60,7 +72,7 @@ runs:
6072
$path = split-path -path $options.Output
6173
$rootPath = split-Path -path $path
6274
Expand-Archive -Path '${{ github.workspace }}\build\build.zip' -DestinationPath $rootPath -Force
63-
Invoke-CITest -Purpose '${{ inputs.purpose }}' -TagSet '${{ inputs.tagSet }}' -OutputFormat JUnitXml
75+
Invoke-CITest -Purpose '${{ inputs.purpose }}' -TagSet '${{ inputs.tagSet }}' -OutputFormat NUnitXml
6476
shell: pwsh
6577

6678
- name: Convert, Publish, and Upload Pester Test Results

build.psm1

+38-19
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ function Get-PesterTag {
12311231
# testing PowerShell remote custom connections.
12321232
function Publish-CustomConnectionTestModule
12331233
{
1234+
Write-LogGroupStart -Title "Publish-CustomConnectionTestModule"
12341235
$sourcePath = "${PSScriptRoot}/test/tools/NamedPipeConnection"
12351236
$outPath = "${PSScriptRoot}/test/tools/NamedPipeConnection/out/Microsoft.PowerShell.NamedPipeConnection"
12361237
$publishPath = "${PSScriptRoot}/test/tools/Modules"
@@ -1255,6 +1256,8 @@ function Publish-CustomConnectionTestModule
12551256
finally {
12561257
Pop-Location
12571258
}
1259+
1260+
Write-LogGroupEnd -Title "Publish-CustomConnectionTestModule"
12581261
}
12591262

12601263
function Publish-PSTestTools {
@@ -1264,6 +1267,7 @@ function Publish-PSTestTools {
12641267
$runtime
12651268
)
12661269

1270+
Write-LogGroupStart -Title "Publish-PSTestTools"
12671271
Find-Dotnet
12681272

12691273
$tools = @(
@@ -1335,6 +1339,7 @@ function Publish-PSTestTools {
13351339

13361340
# Publish the Microsoft.PowerShell.NamedPipeConnection module
13371341
Publish-CustomConnectionTestModule
1342+
Write-LogGroupEnd -Title "Publish-PSTestTools"
13381343
}
13391344

13401345
function Get-ExperimentalFeatureTests {
@@ -1822,12 +1827,16 @@ function Show-PSPesterError
18221827
throw 'Unknown Show-PSPester parameter set'
18231828
}
18241829

1825-
Write-Log -isError -message ("Description: " + $description)
1826-
Write-Log -isError -message ("Name: " + $name)
1827-
Write-Log -isError -message "message:"
1828-
Write-Log -isError -message $message
1829-
Write-Log -isError -message "stack-trace:"
1830-
Write-Log -isError -message $stack_trace
1830+
# Empty line at the end is intentional formatting
1831+
Write-Log -isError -message @"
1832+
Description: $description
1833+
Name: $name
1834+
message:
1835+
$message
1836+
stack-trace:
1837+
$stack_trace
1838+
1839+
"@
18311840

18321841
}
18331842

@@ -1867,13 +1876,17 @@ function Test-XUnitTestResults
18671876
$message = $failure.failure.message
18681877
$stack_trace = $failure.failure.'stack-trace'
18691878

1870-
Write-Log -isError -message ("Description: " + $description)
1871-
Write-Log -isError -message ("Name: " + $name)
1872-
Write-Log -isError -message "message:"
1873-
Write-Log -isError -message $message
1874-
Write-Log -isError -message "stack-trace:"
1875-
Write-Log -isError -message $stack_trace
1876-
Write-Log -isError -message " "
1879+
# Empty line at the end is intentional formatting
1880+
Write-Log -isError -message @"
1881+
Description: $description
1882+
Name: $name
1883+
message:
1884+
$message
1885+
stack-trace:
1886+
$stack_trace
1887+
1888+
"@
1889+
18771890
}
18781891

18791892
throw "$($results.assemblies.assembly.failed) tests failed"
@@ -1909,7 +1922,8 @@ function Test-PSPesterResults
19091922
$x = [xml](Get-Content -Raw $testResultsFile)
19101923
if ([int]$x.'test-results'.failures -gt 0)
19111924
{
1912-
Write-Log -isError -message "TEST FAILURES"
1925+
Write-LogGroupStart -Title 'TEST FAILURES'
1926+
19131927
# switch between methods, SelectNode is not available on dotnet core
19141928
if ( "System.Xml.XmlDocumentXPathExtensions" -as [Type] )
19151929
{
@@ -1923,6 +1937,8 @@ function Test-PSPesterResults
19231937
{
19241938
Show-PSPesterError -testFailure $testfail
19251939
}
1940+
1941+
Write-LogGroupEnd -Title 'TEST FAILURES'
19261942
throw "$($x.'test-results'.failures) tests in $TestArea failed"
19271943
}
19281944
}
@@ -1943,11 +1959,12 @@ function Test-PSPesterResults
19431959
}
19441960
elseif ($ResultObject.FailedCount -gt 0)
19451961
{
1946-
Write-Log -isError -message 'TEST FAILURES'
1962+
Write-LogGroupStart -Title 'TEST FAILURES'
19471963

19481964
$ResultObject.TestResult | Where-Object {$_.Passed -eq $false} | ForEach-Object {
19491965
Show-PSPesterError -testFailureObject $_
19501966
}
1967+
Write-LogGroupEnd -Title 'TEST FAILURES'
19511968

19521969
throw "$($ResultObject.FailedCount) tests in $TestArea failed"
19531970
}
@@ -2694,10 +2711,12 @@ function script:Write-Log
26942711
)
26952712
if ($isError)
26962713
{
2697-
Write-Host -Foreground Red $message
2698-
if($env:GITHUB_WORKFLOW)
2699-
{
2700-
Write-Host "::error::${message}"
2714+
if ($env:GITHUB_WORKFLOW) {
2715+
# https://github.com/actions/toolkit/issues/193#issuecomment-605394935
2716+
$escapedMessage = $message -replace "`n", "%0A" -replace "`r"
2717+
Write-Host "::error::${escapedMessage}"
2718+
} else {
2719+
Write-Host -Foreground Red $message
27012720
}
27022721
}
27032722
else

0 commit comments

Comments
 (0)
0