Skip to content

🩹 [Patch]: BeforeAll/AfterAll-ModuleLocal jobs skipped when setup/teardown scripts do not exist#18

Merged
Marius Storhaug (MariusStorhaug) merged 1 commit intomainfrom
fix/skip-before-after-all-when-scripts-missing
Mar 27, 2026
Merged

🩹 [Patch]: BeforeAll/AfterAll-ModuleLocal jobs skipped when setup/teardown scripts do not exist#18
Marius Storhaug (MariusStorhaug) merged 1 commit intomainfrom
fix/skip-before-after-all-when-scripts-missing

Conversation

@MariusStorhaug
Copy link
Copy Markdown
Member

The BeforeAll-ModuleLocal and AfterAll-ModuleLocal workflow jobs no longer allocate runners when the corresponding tests/BeforeAll.ps1 or tests/AfterAll.ps1 scripts do not exist in the repository. Repositories without setup/teardown scripts now skip these jobs entirely, saving runner time on every workflow run.

Changed: Runner allocation for setup/teardown jobs

Previously, BeforeAll-ModuleLocal and AfterAll-ModuleLocal jobs always spun up a runner — even when the repository had no tests/BeforeAll.ps1 or tests/AfterAll.ps1 script. The runner would check out the repo, invoke the GitHub-Script action, find no script, and exit gracefully. This wasted runner time on every workflow run for the majority of repositories that have no setup/teardown requirements.

Now, the Get-PSModuleSettings action detects whether these scripts exist before setting the run flags. If a script is missing, the corresponding job flag is set to false and the workflow job is skipped before a runner is allocated.

Additionally, AfterAllModuleLocal was previously set to $true unconditionally, relying solely on the workflow-level if: condition to gate it. It now uses the same base conditions as BeforeAllModuleLocal ($shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module)) combined with the script existence check. The workflow-level always() condition remains as an additional safeguard for cleanup-after-failure scenarios.

Repositories that include these scripts are unaffected — both jobs continue to run as before.

Technical Details

  • In src/main.ps1, added Test-Path checks for tests/BeforeAll.ps1 and tests/AfterAll.ps1 in the 'Calculate Job Run Conditions' LogGroup block, before the $run object construction.
  • BeforeAllModuleLocal flag updated from $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) to $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasBeforeAllScript.
  • AfterAllModuleLocal flag updated from $true to $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasAfterAllScript.
  • Added log output for script existence detection, consistent with how other conditions are logged.
  • No workflow YAML changes needed — the existing if: conditions in workflow.yml, BeforeAll-ModuleLocal.yml, and AfterAll-ModuleLocal.yml already respect these flags, and the in-workflow Test-Path guards remain as a safety net.

@MariusStorhaug Marius Storhaug (MariusStorhaug) marked this pull request as ready for review March 27, 2026 21:36
Copilot AI review requested due to automatic review settings March 27, 2026 21:36
@MariusStorhaug Marius Storhaug (MariusStorhaug) merged commit 21c88f4 into main Mar 27, 2026
17 of 18 checks passed
@MariusStorhaug Marius Storhaug (MariusStorhaug) deleted the fix/skip-before-after-all-when-scripts-missing branch March 27, 2026 21:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Get-PSModuleSettings action logic so workflow jobs for module-local setup/teardown (BeforeAll-ModuleLocal, AfterAll-ModuleLocal) can be skipped when the corresponding scripts aren’t present, avoiding unnecessary runner allocation.

Changes:

  • Detects existence of tests/BeforeAll.ps1 and tests/AfterAll.ps1 via Test-Path and logs the results.
  • Gates BeforeAllModuleLocal on tests/BeforeAll.ps1 existence.
  • Gates AfterAllModuleLocal on the same base module-local conditions as other build/test stages plus tests/AfterAll.ps1 existence (instead of $true).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Marius Storhaug (MariusStorhaug) added a commit to PSModule/Process-PSModule that referenced this pull request Mar 27, 2026
…ts are absent (#300)

The `BeforeAll-ModuleLocal` and `AfterAll-ModuleLocal` workflow jobs no
longer allocate runners when the corresponding `tests/BeforeAll.ps1` or
`tests/AfterAll.ps1` scripts do not exist in the repository.
Repositories without setup/teardown scripts now skip these jobs
entirely, saving runner time on every workflow run.

- Fixes #288

## Changed: Runner allocation for setup/teardown jobs

With the `Get-PSModuleSettings` v1.4.4 update, repositories without
`tests/BeforeAll.ps1` or `tests/AfterAll.ps1` no longer allocate runners
for the `BeforeAll-ModuleLocal` and `AfterAll-ModuleLocal` jobs. These
jobs are now skipped entirely at the settings evaluation stage, before
any runner is provisioned.

Previously, both jobs always spun up a runner — even when there was
nothing to execute. The runner would check out the repo, invoke the
GitHub-Script action, find no script, and exit gracefully. This wasted
runner time on every workflow run for the majority of repositories.

Additionally, `AfterAllModuleLocal` was previously set to `$true`
unconditionally. It now uses the same base conditions as
`BeforeAllModuleLocal` combined with the script existence check. The
workflow-level `always()` condition remains as an additional safeguard
for cleanup-after-failure scenarios.

## Technical Details

- Bumps `PSModule/Get-PSModuleSettings` from `v1.4.3` (`3d53e12`) to
`v1.4.4` (`21c88f4`) in `Get-Settings.yml`.
- The action change
([PSModule/Get-PSModuleSettings#18](PSModule/Get-PSModuleSettings#18))
adds `Test-Path` checks for the setup/teardown scripts and sets the
`Run.BeforeAllModuleLocal` / `Run.AfterAllModuleLocal` flags
accordingly, which the existing workflow `if:` conditions already
respect.
- No structural changes to any reusable workflow files — only a SHA pin
update.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip BeforeAll/AfterAll-ModuleLocal jobs when setup/teardown scripts do not exist

2 participants