Skip to content

Commit 6f784e9

Browse files
⚙️ [Maintenance]: Refactor test result aggregation script (#27)
## Summary Refactors `Get-AggregatedStatus.ps1` to align with the improved implementation pattern used in `Invoke-Pester/tests/Test-ActionResults.ps1`. ## Changes ### Refactored - **Test aggregation script**: Restructured to use cleaner data patterns and improved code organization ## Details - Added proper script header with comment-based help, `[CmdletBinding()]`, and `param()` - Replaced pre-computed variables with nested hashtable structure (`@{ Actual = ...; Expected = ... }`) - Separated job data from presentation by processing into a `$results` array with computed pass values - Changed iteration from `ForEach-Object` to `foreach` for better readability - Changed `Write-Warning` to `Write-Error` for actual validation failures - Removed redundant debug statements - Added `| Out-String` to `Format-List` for proper output - Updated summary table to use `$results` instead of raw `$jobs` ## Type of Change - [x] ⚙️ Maintenance - Test infrastructure improvements
1 parent 5955a61 commit 6f784e9

File tree

1 file changed

+56
-80
lines changed

1 file changed

+56
-80
lines changed

tests/Get-AggregatedStatus.ps1

Lines changed: 56 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
'Markdown' | ForEach-Object {
1+
<#
2+
.DESCRIPTION
3+
Aggregates and validates test results from all Action-Test workflow jobs.
4+
Compares actual outcomes against expected values and generates a summary report.
5+
#>
6+
7+
[CmdletBinding()]
8+
param()
9+
10+
# Install and import the Markdown module for generating summary tables
11+
'Markdown' | ForEach-Object {
212
$name = $_
313
Write-Output "Installing module: $name"
414
$retryCount = 5
@@ -19,102 +29,68 @@
1929
Import-Module -Name $name
2030
}
2131

22-
# Build an array of objects for each job
23-
$SourceCodeExpectedOutcome = 'success'
24-
$SourceCodeOutcomeResult = $env:SourceCodeOutcome -eq $SourceCodeExpectedOutcome
25-
$SourceCodeExpectedConclusion = 'success'
26-
$SourceCodeConclusionResult = $env:SourceCodeConclusion -eq $SourceCodeExpectedConclusion
27-
28-
$CustomExpectedOutcome = 'success'
29-
$CustomOutcomeResult = $env:CustomOutcome -eq $CustomExpectedOutcome
30-
$CustomExpectedConclusion = 'success'
31-
$CustomConclusionResult = $env:CustomConclusion -eq $CustomExpectedConclusion
32-
33-
$WithManifestExpectedOutcome = 'failure'
34-
$WithManifestOutcomeResult = $env:WithManifestOutcome -eq $WithManifestExpectedOutcome
35-
$WithManifestExpectedConclusion = 'success'
36-
$WithManifestConclusionResult = $env:WithManifestConclusion -eq $WithManifestExpectedConclusion
37-
38-
$WithManifestDefaultExpectedOutcome = 'failure'
39-
$WithManifestDefaultOutcomeResult = $env:WithManifestDefaultOutcome -eq $WithManifestDefaultExpectedOutcome
40-
$WithManifestDefaultExpectedConclusion = 'success'
41-
$WithManifestDefaultConclusionResult = $env:WithManifestDefaultConclusion -eq $WithManifestDefaultExpectedConclusion
42-
43-
$OutputsExpectedOutcome = 'success'
44-
$OutputsOutcomeResult = $env:OutputsOutcome -eq $OutputsExpectedOutcome
45-
$OutputsExpectedConclusion = 'success'
46-
$OutputsConclusionResult = $env:OutputsConclusion -eq $OutputsExpectedConclusion
47-
32+
# Build test job objects with expected vs actual values
4833
$jobs = @(
49-
[PSCustomObject]@{
50-
Name = 'Action-Test - [Src-SourceCode]'
51-
Outcome = $env:SourceCodeOutcome
52-
ExpectedOutcome = $SourceCodeExpectedOutcome
53-
PassedOutcome = $SourceCodeOutcomeResult
54-
Conclusion = $env:SourceCodeConclusion
55-
ExpectedConclusion = $SourceCodeExpectedConclusion
56-
PassedConclusion = $SourceCodeConclusionResult
57-
},
58-
[PSCustomObject]@{
59-
Name = 'Action-Test - [Src-Custom]'
60-
Outcome = $env:CustomOutcome
61-
ExpectedOutcome = $CustomExpectedOutcome
62-
PassedOutcome = $CustomOutcomeResult
63-
Conclusion = $env:CustomConclusion
64-
ExpectedConclusion = $CustomExpectedConclusion
65-
PassedConclusion = $CustomConclusionResult
66-
},
67-
[PSCustomObject]@{
68-
Name = 'Action-Test - [Src-WithManifest]'
69-
Outcome = $env:WithManifestOutcome
70-
ExpectedOutcome = $WithManifestExpectedOutcome
71-
PassedOutcome = $WithManifestOutcomeResult
72-
Conclusion = $env:WithManifestConclusion
73-
ExpectedConclusion = $WithManifestExpectedConclusion
74-
PassedConclusion = $WithManifestConclusionResult
75-
},
76-
[PSCustomObject]@{
77-
Name = 'Action-Test - [Src-WithManifest-Default]'
78-
Outcome = $env:WithManifestDefaultOutcome
79-
ExpectedOutcome = $WithManifestDefaultExpectedOutcome
80-
PassedOutcome = $WithManifestDefaultOutcomeResult
81-
Conclusion = $env:WithManifestDefaultConclusion
82-
ExpectedConclusion = $WithManifestDefaultExpectedConclusion
83-
PassedConclusion = $WithManifestDefaultConclusionResult
84-
},
85-
[PSCustomObject]@{
86-
Name = 'Action-Test - [outputs]'
87-
Outcome = $env:OutputsOutcome
88-
ExpectedOutcome = $OutputsExpectedOutcome
89-
PassedOutcome = $OutputsOutcomeResult
90-
Conclusion = $env:OutputsConclusion
91-
ExpectedConclusion = $OutputsExpectedConclusion
92-
PassedConclusion = $OutputsConclusionResult
34+
@{
35+
Name = 'Action-Test - [Src-SourceCode]'
36+
Outcome = @{ Actual = $env:SourceCodeOutcome; Expected = 'success' }
37+
Conclusion = @{ Actual = $env:SourceCodeConclusion; Expected = 'success' }
38+
}
39+
@{
40+
Name = 'Action-Test - [Src-Custom]'
41+
Outcome = @{ Actual = $env:CustomOutcome; Expected = 'success' }
42+
Conclusion = @{ Actual = $env:CustomConclusion; Expected = 'success' }
43+
}
44+
@{
45+
Name = 'Action-Test - [Src-WithManifest]'
46+
Outcome = @{ Actual = $env:WithManifestOutcome; Expected = 'failure' }
47+
Conclusion = @{ Actual = $env:WithManifestConclusion; Expected = 'success' }
48+
}
49+
@{
50+
Name = 'Action-Test - [Src-WithManifest-Default]'
51+
Outcome = @{ Actual = $env:WithManifestDefaultOutcome; Expected = 'failure' }
52+
Conclusion = @{ Actual = $env:WithManifestDefaultConclusion; Expected = 'success' }
53+
}
54+
@{
55+
Name = 'Action-Test - [outputs]'
56+
Outcome = @{ Actual = $env:OutputsOutcome; Expected = 'success' }
57+
Conclusion = @{ Actual = $env:OutputsConclusion; Expected = 'success' }
9358
}
9459
)
9560

61+
# Add Pass property to each check and convert to PSCustomObject for table output
62+
$results = $jobs | ForEach-Object {
63+
[PSCustomObject]@{
64+
Name = $_.Name
65+
Outcome = $_.Outcome.Actual
66+
OutcomeExpected = $_.Outcome.Expected
67+
OutcomePass = $_.Outcome.Actual -eq $_.Outcome.Expected
68+
Conclusion = $_.Conclusion.Actual
69+
ConclusionExpected = $_.Conclusion.Expected
70+
ConclusionPass = $_.Conclusion.Actual -eq $_.Conclusion.Expected
71+
}
72+
}
73+
9674
# Display the table in the workflow logs
97-
$jobs | Format-List
75+
$results | Format-List | Out-String
9876

9977
$passed = $true
100-
$jobs | ForEach-Object {
101-
if (-not $_.PassedOutcome) {
102-
Write-Warning "Job $($_.Name) failed with Outcome $($_.Outcome) and Expected Outcome $($_.ExpectedOutcome)"
78+
foreach ($job in $results) {
79+
if (-not $job.OutcomePass) {
80+
Write-Error "Job $($job.Name) failed with Outcome $($job.Outcome) and Expected Outcome $($job.OutcomeExpected)"
10381
$passed = $false
104-
Write-Warning "Passed: $passed"
10582
}
10683

107-
if (-not $_.PassedConclusion) {
108-
Write-Warning "Job $($_.Name) failed with Conclusion $($_.Conclusion) and Expected Conclusion $($_.ExpectedConclusion)"
84+
if (-not $job.ConclusionPass) {
85+
Write-Error "Job $($job.Name) failed with Conclusion $($job.Conclusion) and Expected Conclusion $($job.ConclusionExpected)"
10986
$passed = $false
110-
Write-Warning "Passed: $passed"
11187
}
11288
}
11389

11490
$icon = if ($passed) { '' } else { '' }
11591
$status = Heading 1 "$icon - GitHub Actions Status" {
11692
Table {
117-
$jobs
93+
$results
11894
}
11995
}
12096

0 commit comments

Comments
 (0)