Skip to content

Commit 317bcb1

Browse files
Treat BeforeAll module-local setup failures as catastrophic (#399)
## Summary - treat `BeforeAll-ModuleLocal` failure as a hard failure root cause in test result aggregation - run `AfterAll-ModuleLocal` cleanup whenever module-local setup ran, even if setup failed and tests were skipped - pass `BeforeAll-ModuleLocal` job result into `Get-TestResults` and fail early with a clear root-cause message - document the new `BeforeAllModuleLocalResult` input in `Get-PesterTestResults` ## Links - Closes #388 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 025d6a2 commit 317bcb1

5 files changed

Lines changed: 31 additions & 5 deletions

File tree

.github/actions/Get-PesterTestResults/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ or missing results. It supports three categories of test suites: Source Code, PS
1818
| `SourceCodeTestSuites` | JSON array specifying OS names for Source Code test suites. Example: `[{"OSName": "Windows"}]` | Yes | |
1919
| `PSModuleTestSuites` | JSON array specifying OS names for PSModule test suites. Example: `[{"OSName": "Linux"}]` | Yes | |
2020
| `ModuleTestSuites` | JSON array specifying TestName and OSName for Module test suites. Example: `[{"TestName": "Integration", "OSName": "MacOS"}]` | Yes | |
21+
| `BeforeAllModuleLocalResult` | Workflow result for the `BeforeAll-ModuleLocal` job (`success`, `failure`, `skipped`). | No | `skipped` |
2122
| `Debug` | Enable debug output (`true`/`false`). | No | `false` |
2223
| `Verbose` | Enable verbose output (`true`/`false`). | No | `false` |
2324
| `Version` | Exact version of the GitHub module to install (e.g., `1.0.0`). | No | Latest |
@@ -50,5 +51,6 @@ This action does not define explicit outputs. Instead:
5051
- **Test Suite Inputs**: Must be valid JSON arrays.
5152
- `SourceCodeTestSuites` and `PSModuleTestSuites` require `OSName`.
5253
- `ModuleTestSuites` requires both `TestName` and `OSName`.
54+
- **BeforeAll module-local failures**: When `BeforeAllModuleLocalResult` is `failure`, the action exits immediately and reports the setup failure as the root cause.
5355
- **Artifact Names**: The action expects artifacts named `*-TestResults` containing Pester JSON reports.
5456
- **Failure Conditions**: The action fails if tests are unexecuted, explicitly failed, or if result files are missing.

.github/actions/Get-PesterTestResults/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
ModuleTestSuites:
1616
description: The test suites to run for the module.
1717
required: true
18+
BeforeAllModuleLocalResult:
19+
description: The workflow result for the BeforeAll-ModuleLocal job.
20+
required: false
21+
default: skipped
1822
Debug:
1923
description: Enable debug output.
2024
required: false
@@ -44,6 +48,7 @@ runs:
4448
PSMODULE_GET_PESTERTESTRESULTS_INPUT_SourceCodeTestSuites: ${{ inputs.SourceCodeTestSuites }}
4549
PSMODULE_GET_PESTERTESTRESULTS_INPUT_PSModuleTestSuites: ${{ inputs.PSModuleTestSuites }}
4650
PSMODULE_GET_PESTERTESTRESULTS_INPUT_ModuleTestSuites: ${{ inputs.ModuleTestSuites }}
51+
PSMODULE_GET_PESTERTESTRESULTS_INPUT_BeforeAllModuleLocalResult: ${{ inputs.BeforeAllModuleLocalResult }}
4752
with:
4853
Name: Get-PesterTestResults
4954
Debug: ${{ inputs.Debug }}

.github/actions/Get-PesterTestResults/src/main.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ param()
1010
$owner = $env:GITHUB_REPOSITORY_OWNER
1111
$repo = $env:GITHUB_REPOSITORY_NAME
1212
$runId = $env:GITHUB_RUN_ID
13+
$beforeAllModuleLocalResult = $env:PSMODULE_GET_PESTERTESTRESULTS_INPUT_BeforeAllModuleLocalResult
14+
15+
if ($beforeAllModuleLocalResult -eq 'failure') {
16+
Write-GitHubError (
17+
'BeforeAll-ModuleLocal failed. Module-local tests were skipped as a safety stop, ' +
18+
'and AfterAll-ModuleLocal cleanup was still requested. ' +
19+
'See the BeforeAll-ModuleLocal job log for the root cause.'
20+
)
21+
exit 1
22+
}
1323

1424
$files = Get-GitHubArtifact -Owner $owner -Repository $repo -WorkflowRunID $runId -Name '*-TestResults' |
1525
Save-GitHubArtifact -Path 'TestResults' -Force -Expand -PassThru | Get-ChildItem -Recurse -Filter *.json | Sort-Object Name -Unique

.github/workflows/Get-TestResults.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ on:
77
type: string
88
description: The complete settings object including test suites.
99
required: true
10+
BeforeAllModuleLocalResult:
11+
type: string
12+
description: The workflow result for the BeforeAll-ModuleLocal job.
13+
required: false
14+
default: skipped
1015

1116
permissions:
1217
contents: read # to checkout the repo
@@ -31,6 +36,7 @@ jobs:
3136
SourceCodeTestSuites: ${{ toJSON(fromJson(inputs.Settings).TestSuites.SourceCode) }}
3237
PSModuleTestSuites: ${{ toJSON(fromJson(inputs.Settings).TestSuites.PSModule) }}
3338
ModuleTestSuites: ${{ toJSON(fromJson(inputs.Settings).TestSuites.Module) }}
39+
BeforeAllModuleLocalResult: ${{ inputs.BeforeAllModuleLocalResult }}
3440
Debug: ${{ fromJson(inputs.Settings).Debug }}
3541
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}
3642
Verbose: ${{ fromJson(inputs.Settings).Verbose }}

.github/workflows/workflow.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,18 @@ jobs:
186186
Settings: ${{ needs.Plan.outputs.Settings }}
187187

188188
# Runs on:
189-
# - ✅ Open/Updated PR - Runs teardown scripts after local module tests
190-
# - ✅ Merged PR - Runs teardown scripts after local module tests
191-
# - ✅ Abandoned PR - Runs teardown if tests were started (cleanup)
192-
# - ✅ Manual run - Runs teardown scripts after local module tests
189+
# - ✅ Open/Updated PR - Runs teardown scripts after local module setup/tests
190+
# - ✅ Merged PR - Runs teardown scripts after local module setup/tests
191+
# - ✅ Abandoned PR - Runs teardown if local module setup/tests were started (cleanup)
192+
# - ✅ Manual run - Runs teardown scripts after local module setup/tests
193193
AfterAll-ModuleLocal:
194-
if: fromJson(needs.Plan.outputs.Settings).Run.AfterAllModuleLocal && needs.Test-ModuleLocal.result != 'skipped' && always()
194+
if: fromJson(needs.Plan.outputs.Settings).Run.AfterAllModuleLocal && needs.BeforeAll-ModuleLocal.result != 'skipped' && always()
195195
uses: ./.github/workflows/AfterAll-ModuleLocal.yml
196196
secrets:
197197
TestData: ${{ secrets.TestData }}
198198
needs:
199199
- Plan
200+
- BeforeAll-ModuleLocal
200201
- Test-ModuleLocal
201202
with:
202203
Settings: ${{ needs.Plan.outputs.Settings }}
@@ -213,10 +214,12 @@ jobs:
213214
- Test-SourceCode
214215
- Lint-SourceCode
215216
- Test-Module
217+
- BeforeAll-ModuleLocal
216218
- Test-ModuleLocal
217219
uses: ./.github/workflows/Get-TestResults.yml
218220
with:
219221
Settings: ${{ needs.Plan.outputs.Settings }}
222+
BeforeAllModuleLocalResult: ${{ needs.BeforeAll-ModuleLocal.result }}
220223

221224
# Runs on:
222225
# - ✅ Open/Updated PR - Calculates and reports code coverage

0 commit comments

Comments
 (0)