@@ -24,6 +24,7 @@ $testIgnoredCount = 0
2424$testSkippedCount = 0
2525$testInvalidCount = 0
2626
27+ # Process test results and generate annotations for failures
2728Get-ChildItem - Path " ${TestResultsFolder} /*.xml" - Recurse | ForEach-Object {
2829 $results = [xml ] (get-content $_.FullName )
2930
@@ -35,6 +36,61 @@ Get-ChildItem -Path "${TestResultsFolder}/*.xml" -Recurse | ForEach-Object {
3536 $testIgnoredCount += [int ]$results .' test-results' .ignored
3637 $testSkippedCount += [int ]$results .' test-results' .skipped
3738 $testInvalidCount += [int ]$results .' test-results' .invalid
39+
40+ # Generate GitHub Actions annotations for test failures
41+ # Select failed test cases
42+ if (" System.Xml.XmlDocumentXPathExtensions" -as [Type ]) {
43+ $failures = [System.Xml.XmlDocumentXPathExtensions ]::SelectNodes($results .' test-results' , ' .//test-case[@result = "Failure"]' )
44+ }
45+ else {
46+ $failures = $results.SelectNodes (' .//test-case[@result = "Failure"]' )
47+ }
48+
49+ foreach ($testfail in $failures ) {
50+ $description = $testfail.description
51+ $testName = $testfail.name
52+ $message = $testfail.failure.message
53+ $stack_trace = $testfail.failure .' stack-trace'
54+
55+ # Parse stack trace to get file and line info
56+ $fileInfo = Get-PesterFailureFileInfo - StackTraceString $stack_trace
57+
58+ if ($fileInfo.File ) {
59+ # Convert absolute path to relative path for GitHub Actions
60+ $filePath = $fileInfo.File
61+
62+ # GitHub Actions expects paths relative to the workspace root
63+ if ($env: GITHUB_WORKSPACE ) {
64+ $workspacePath = $env: GITHUB_WORKSPACE
65+ if ($filePath.StartsWith ($workspacePath )) {
66+ $filePath = $filePath.Substring ($workspacePath.Length ).TrimStart(' /' , ' \' )
67+ # Normalize to forward slashes for consistency
68+ $filePath = $filePath -replace ' \\' , ' /'
69+ }
70+ }
71+
72+ # Create annotation title
73+ $annotationTitle = " Test Failure: $description / $testName "
74+
75+ # Build the annotation message
76+ $annotationMessage = $message -replace " `n " , " %0A" -replace " `r "
77+
78+ # Build and output the workflow command
79+ $workflowCommand = " ::error file=$filePath "
80+ if ($fileInfo.Line ) {
81+ $workflowCommand += " ,line=$ ( $fileInfo.Line ) "
82+ }
83+ $workflowCommand += " ,title=$annotationTitle ::$annotationMessage "
84+
85+ Write-Host $workflowCommand
86+
87+ # Output a link to the test run
88+ if ($env: GITHUB_SERVER_URL -and $env: GITHUB_REPOSITORY -and $env: GITHUB_RUN_ID ) {
89+ $logUrl = " $ ( $env: GITHUB_SERVER_URL ) /$ ( $env: GITHUB_REPOSITORY ) /actions/runs/$ ( $env: GITHUB_RUN_ID ) "
90+ Write-Host " Test logs: $logUrl "
91+ }
92+ }
93+ }
3894}
3995
4096@"
0 commit comments