@@ -45,16 +45,18 @@ jobs:
45
45
46
46
- name : Run quarantined tests
47
47
run : |
48
- ${{ env.BUILD_SCRIPT }} -projects ${{ github.workspace }}/tests/Shared/SolutionTests.proj -restore -build -test -c Release /p:IsGitHubActions=true /p:RunQuarantinedTests=true /bl:${{ github.workspace }}/artifacts/log/Release/test-quarantined.binlog
48
+ ${{ env.BUILD_SCRIPT }} -projects ${{ github.workspace }}/tests/Shared/SolutionTests.proj -restore -build -test -c Release /p:IsGitHubActions=true /p:RunQuarantinedTests=true /bl:${{ github.workspace }}/artifacts/log/Release/test-quarantined.binlog
49
49
50
50
- name : Keep only relevant test logs
51
+ if : always()
51
52
shell : pwsh
52
53
run : |
53
54
# Define the directory to search for log files
54
55
$logDirectory = "${{ github.workspace }}/artifacts/log/**/TestLogs"
55
56
56
57
# Define the text to search for in the log files
57
58
$searchText = "No test matches the given testcase filter"
59
+ $resultsFilePattern = "Results File: (.+)"
58
60
59
61
# Get all .log files in the specified directory and its subdirectories
60
62
$logFiles = Get-ChildItem -Path $logDirectory -Filter *.log -Recurse
@@ -69,14 +71,96 @@ jobs:
69
71
Remove-Item -Path $logFile.FullName -Force
70
72
Write-Host "Removed file: $($logFile.FullName)"
71
73
}
74
+ else {
75
+ # Extract paths from lines containing "Results File: <path>"
76
+ foreach ($line in $content) {
77
+ if ($line -match $resultsFilePattern) {
78
+ $resultsFilePath = $matches[1]
79
+ Write-Host "Found results file: $resultsFilePath"
80
+
81
+ # Copy the results file to the TestLogs folder
82
+ $destinationPath = (Split-Path -Path $logFile.FullName -Parent)
83
+ Copy-Item -Path $resultsFilePath -Destination $destinationPath -Force
84
+ Write-Host "Copied $resultsFilePath to $destinationPath"
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ - name : Process logs and post results
91
+ if : always()
92
+ shell : pwsh
93
+ run : |
94
+ $logDirectory = "${{ github.workspace }}/artifacts/log/**/TestLogs"
95
+ $trxFiles = Get-ChildItem -Path $logDirectory -Filter *.trx -Recurse
96
+
97
+ $testResults = @() # Initialize an array to store test results
98
+
99
+ foreach ($trxFile in $trxFiles) {
100
+ # Load the .trx file as XML
101
+ $xmlContent = [xml](Get-Content -Path $trxFile.FullName)
102
+
103
+ # Extract test results from the XML
104
+ foreach ($testResult in $xmlContent.TestRun.Results.UnitTestResult) {
105
+ $testName = $testResult.testName
106
+ $outcome = $testResult.outcome
107
+ $duration = $testResult.duration
108
+
109
+ # Map outcome to emoji
110
+ switch ($outcome) {
111
+ "Passed" { $emoji = "✔️" }
112
+ "Failed" { $emoji = "❌" }
113
+ default { $emoji = "❔" }
114
+ }
115
+
116
+ # Normalize the duration to a consistent format (hh:mm:ss.fff)
117
+ $normalizedDuration = [TimeSpan]::Parse($duration).ToString("mm\:ss\.fff")
118
+
119
+ # Add the test result to the array
120
+ $testResults += [PSCustomObject]@{
121
+ TestName = $testName
122
+ Outcome = $outcome
123
+ OutcomeIcon = $emoji
124
+ Duration = $normalizedDuration
125
+ }
126
+ }
72
127
}
73
128
129
+ # Sort the test results by test name
130
+ $testResults = $testResults | Sort-Object -Property TestName
131
+
132
+ # Calculate summary statistics
133
+ $totalTests = $testResults.Count
134
+ $passedTests = ($testResults | Where-Object { $_.Outcome -eq "Passed" }).Count
135
+ $failedTests = ($testResults | Where-Object { $_.Outcome -eq "Failed" }).Count
136
+ $skippedTests = ($testResults | Where-Object { $_.Outcome -eq "NotExecuted" }).Count
137
+
138
+ # Add the summary to the annotation
139
+ $summary = "total: $totalTests, passed: $passedTests, failed: $failedTests, skipped: $skippedTests"
140
+ if ($failedTests -gt 0) {
141
+ Write-Host "::error::Tests Summary: $summary"
142
+ } else {
143
+ Write-Host "::notice::Tests Summary: $summary"
144
+ }
145
+
146
+ # Format the test results as a console-friendly table
147
+ $tableHeader = "{0,-16} {1,-150} {2,-20}" -f "Duration", "Test Name", "Result"
148
+ $tableSeparator = "-" * 185
149
+ $tableRows = $testResults | ForEach-Object { "{0,-16} {1,-150} {2,-20}" -f $_.Duration, $_.TestName, "$($_.OutcomeIcon) $($_.Outcome)" }
150
+ $table = "$tableHeader`n$tableSeparator`n" + ($tableRows -join "`n") + "`n$tableSeparator`n"
151
+ Write-Host "`nTest Results:`n`n$table"
152
+
153
+ # Optionally, save the results to a file for further processing
154
+ $outputPath = "${{ github.workspace }}/artifacts/log/Release/TestLogs/summary.log"
155
+ $table | Out-File -FilePath $outputPath -Encoding utf8
156
+ Write-Host "Test results saved to $outputPath"
157
+
74
158
- name : Upload logs, and test results
75
159
if : always()
76
160
uses : actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1
77
161
with :
78
162
name : logs-${{ matrix.os.name }}
79
163
path : |
80
- ${{ github.workspace }}/artifacts/log/** /*.binlog
81
- ${{ github.workspace }}/artifacts/log/** /TestLogs/**
82
- ${{ github.workspace }}/TestResults/**
164
+ ${{ github.workspace }}/artifacts/log/*/*.binlog
165
+ ${{ github.workspace }}/artifacts/log/*/TestLogs/**
166
+ retention-days : 5
0 commit comments