-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
When a module repository does not have tests/BeforeAll.ps1 or tests/AfterAll.ps1, the BeforeAll-ModuleLocal and AfterAll-ModuleLocal jobs still spin up a runner, checkout the repo, and run the GitHub-Script action — only to discover the script doesn't exist and exit successfully:
Run PSModule/GitHub-Script@0097f3bbe3f413f3b577b9bcc600727b0ca3201a
Run # AfterAll-ModuleLocal
Running AfterAll Teardown Scripts
No AfterAll.ps1 script found at [tests/AfterAll.ps1] - exiting successfully
This wastes runner time for every workflow run on repositories that don't use setup/teardown scripts (which is the majority of modules).
Current behavior
In Get-PSModuleSettings, the run flags are set as:
BeforeAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module)
AfterAllModuleLocal = $true # Always runs if Test-ModuleLocal was not skippedNeither flag checks whether tests/BeforeAll.ps1 or tests/AfterAll.ps1 actually exists. The existence check happens inside the workflow step itself, after a runner has already been allocated.
Proposed solution
During Get-Settings, check for the existence of tests/BeforeAll.ps1 and tests/AfterAll.ps1 in the repository and incorporate that into the Run flags:
$hasBeforeAllScript = Test-Path -Path 'tests/BeforeAll.ps1'
$hasAfterAllScript = Test-Path -Path 'tests/AfterAll.ps1'
# ...
BeforeAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasBeforeAllScript
AfterAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasAfterAllScriptThis would skip the entire job when the scripts don't exist, avoiding unnecessary runner allocation.
Affected components
- Get-PSModuleSettings (
src/main.ps1) — add file existence checks - workflow.yml — no changes needed (already respects
Run.BeforeAllModuleLocal/Run.AfterAllModuleLocal) - BeforeAll-ModuleLocal.yml / AfterAll-ModuleLocal.yml — the internal
Test-Pathguard can remain as a safety net