Skip to content

Commit f8fef53

Browse files
🩹 [Patch]: Enhance GitHub Actions workflows with aggregated job status reporting and improved error handling
1 parent aaa2e3b commit f8fef53

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

.github/workflows/Action-Test.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,118 @@ jobs:
4949
TestType: outputs
5050
Path: tests/outputTestRepo/outputs/modules/PSModuleTest
5151
Settings: Module
52+
53+
54+
CatchJob:
55+
name: "Catch Job - Aggregate Status"
56+
needs:
57+
- ActionTestSrcSourceCode
58+
- ActionTestSrcCustom
59+
- ActionTestSrcWithManifest
60+
- ActionTestOutputs
61+
if: always()
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Display Aggregated Results as a Table
65+
uses: PSModule/Github-Script@v1
66+
with:
67+
Script: |
68+
Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository
69+
70+
# Build an array of objects for each job
71+
$ActionTestSrcSourceCodeOutcome = ${{ needs.ActionTestSrcSourceCode.outputs.Outcome }}
72+
$ActionTestSrcSourceCodeExpectedOutcome = "success"
73+
$ActionTestSrcSourceCodeOutcomeResult = $ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome
74+
$ActionTestSrcSourceCodeConclusion = ${{ needs.ActionTestSrcSourceCode.outputs.Conclusion }}
75+
$ActionTestSrcSourceCodeExpectedConclusion = "success"
76+
$ActionTestSrcSourceCodeConclusionResult = $ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion
77+
78+
$ActionTestSrcCustomOutcome = ${{ needs.ActionTestSrcCustom.outputs.Outcome }}
79+
$ActionTestSrcCustomExpectedOutcome = "success"
80+
$ActionTestSrcCustomOutcomeResult = $ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome
81+
$ActionTestSrcCustomConclusion = ${{ needs.ActionTestSrcCustom.outputs.Conclusion }}
82+
$ActionTestSrcCustomExpectedConclusion = "success"
83+
$ActionTestSrcCustomConclusionResult = $ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion
84+
85+
$ActionTestSrcWithManifestOutcome = ${{ needs.ActionTestSrcWithManifest.outputs.Outcome }}
86+
$ActionTestSrcWithManifestExpectedOutcome = "failure"
87+
$ActionTestSrcWithManifestOutcomeResult = $ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome
88+
$ActionTestSrcWithManifestConclusion = ${{ needs.ActionTestSrcWithManifest.outputs.Conclusion }}
89+
$ActionTestSrcWithManifestExpectedConclusion = "success"
90+
$ActionTestSrcWithManifestConclusionResult = $ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion
91+
92+
$ActionTestOutputsOutcome = ${{ needs.ActionTestOutputs.outputs.Outcome }}
93+
$ActionTestOutputsExpectedOutcome = "success"
94+
$ActionTestOutputsOutcomeResult = $ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome
95+
$ActionTestOutputsConclusion = ${{ needs.ActionTestOutputs.outputs.Conclusion }}
96+
$ActionTestOutputsExpectedConclusion = "success"
97+
$ActionTestOutputsConclusionResult = $ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion
98+
99+
$jobs = @(
100+
[PSCustomObject]@{
101+
Name = "Action-Test - [Src-SourceCode]"
102+
Outcome = $ActionTestSrcSourceCodeOutcome
103+
ExpectedOutcome = $ActionTestSrcSourceCodeExpectedOutcome
104+
PassedOutcome = $ActionTestSrcSourceCodeOutcomeResult
105+
Conclusion = $ActionTestSrcSourceCodeConclusion
106+
ExpectedConclusion = $ActionTestSrcSourceCodeExpectedConclusion
107+
PassedConclusion = $ActionTestSrcSourceCodeConclusionResult
108+
},
109+
[PSCustomObject]@{
110+
Name = "Action-Test - [Src-Custom]"
111+
Outcome = $ActionTestSrcCustomOutcome
112+
ExpectedOutcome = $ActionTestSrcCustomExpectedOutcome
113+
PassedOutcome = $ActionTestSrcCustomOutcomeResult
114+
Conclusion = $ActionTestSrcCustomConclusion
115+
ExpectedConclusion = $ActionTestSrcCustomExpectedConclusion
116+
PassedConclusion = $ActionTestSrcCustomConclusionResult
117+
},
118+
[PSCustomObject]@{
119+
Name = "Action-Test - [Src-WithManifest]"
120+
Outcome = $ActionTestSrcWithManifestOutcome
121+
ExpectedOutcome = $ActionTestSrcWithManifestExpectedOutcome
122+
PassedOutcome = $ActionTestSrcWithManifestOutcomeResult
123+
Conclusion = $ActionTestSrcWithManifestConclusion
124+
ExpectedConclusion = $ActionTestSrcWithManifestExpectedConclusion
125+
PassedConclusion = $ActionTestSrcWithManifestConclusionResult
126+
},
127+
[PSCustomObject]@{
128+
Name = "Action-Test - [outputs]"
129+
Outcome = $ActionTestOutputsOutcome
130+
ExpectedOutcome = $ActionTestOutputsExpectedOutcome
131+
PassedOutcome = $ActionTestOutputsOutcomeResult
132+
Conclusion = $ActionTestOutputsConclusion
133+
ExpectedConclusion = $ActionTestOutputsExpectedConclusion
134+
PassedConclusion = $ActionTestOutputsConclusionResult
135+
}
136+
)
137+
138+
# Display the table in the workflow logs
139+
$jobs | Format-List
140+
141+
$passed = $true
142+
$jobs | ForEach-Object {
143+
if (-not $_.PassedOutcome) {
144+
Write-Error "Job $($_.Name) failed with Outcome $($_.Outcome) and Expected Outcome $($_.ExpectedOutcome)"
145+
$passed = $false
146+
}
147+
148+
if (-not $_.PassedConclusion) {
149+
Write-Error "Job $($_.Name) failed with Conclusion $($_.Conclusion) and Expected Conclusion $($_.ExpectedConclusion)"
150+
$passed = $false
151+
}
152+
}
153+
154+
$icon = if ($passed) { '✅' } else { '❌' }
155+
$status = Heading 1 "$icon - GitHub Actions Status" {
156+
Table {
157+
$jobs
158+
}
159+
}
160+
161+
Set-GitHubStepSummary -Summary $status
162+
163+
if (-not $passed) {
164+
Write-GithubError "One or more jobs failed"
165+
exit 1
166+
}

.github/workflows/ActionTestWorkflow.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ jobs:
2424
os: [ubuntu-latest, macos-latest, windows-latest]
2525
name: ${{ matrix.os }}
2626
runs-on: ${{ matrix.os }}
27+
outputs:
28+
outcome: ${{ steps.action-test.outcome }}
29+
conclusion: ${{ steps.action-test.conclusion }}
2730
steps:
2831
- name: Checkout repo
2932
uses: actions/checkout@v4
3033

3134
- name: Action-Test
3235
uses: ./
36+
continue-on-error: true
3337
id: action-test
3438
with:
3539
Path: ${{ inputs.Path }}

scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ BeforeDiscovery {
6565

6666
Describe 'PSScriptAnalyzer' {
6767
BeforeAll {
68-
$PSStyle.OutputRendering = 'Host'
6968
$relativeSettingsFilePath = if ($SettingsFilePath.StartsWith($PSScriptRoot)) {
7069
$SettingsFilePath.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/')
7170
} elseif ($SettingsFilePath.StartsWith($env:GITHUB_WORKSPACE)) {
@@ -115,3 +114,7 @@ Describe 'PSScriptAnalyzer' {
115114
}
116115
}
117116
}
117+
118+
AfterAll {
119+
$PSStyle.OutputRendering = 'Host'
120+
}

0 commit comments

Comments
 (0)