Skip to content

Commit 21c88f4

Browse files
🩹 [Patch]: BeforeAll/AfterAll-ModuleLocal jobs skipped when setup/teardown scripts do not exist (#18)
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 PSModule/Process-PSModule#288 ## 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.
1 parent 8ec4c9e commit 21c88f4

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎src/main.ps1‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,16 +531,23 @@ LogGroup 'Calculate Job Run Conditions:' {
531531
# Note: $shouldPrerelease already requires $hasImportantChanges, so no separate check needed.
532532
$shouldRunBuildTest = $isNotAbandonedPR -and $hasImportantChanges
533533

534+
# Check if setup/teardown scripts exist in the repository
535+
$hasBeforeAllScript = Test-Path -Path 'tests/BeforeAll.ps1'
536+
$hasAfterAllScript = Test-Path -Path 'tests/AfterAll.ps1'
537+
Write-Host "Setup/teardown script detection:"
538+
Write-Host " tests/BeforeAll.ps1 exists: $hasBeforeAllScript"
539+
Write-Host " tests/AfterAll.ps1 exists: $hasAfterAllScript"
540+
534541
# Create Run object with all job-specific conditions
535542
$run = [pscustomobject]@{
536543
LintRepository = $isOpenOrUpdatedPR -and (-not $settings.Linter.Skip)
537544
BuildModule = $shouldRunBuildTest -and (-not $settings.Build.Module.Skip)
538545
TestSourceCode = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.SourceCode)
539546
LintSourceCode = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.SourceCode)
540547
TestModule = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.PSModule)
541-
BeforeAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module)
548+
BeforeAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasBeforeAllScript
542549
TestModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module)
543-
AfterAllModuleLocal = $true # Always runs if Test-ModuleLocal was not skipped
550+
AfterAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasAfterAllScript
544551
GetTestResults = $shouldRunBuildTest -and (-not $settings.Test.TestResults.Skip) -and (
545552
($null -ne $settings.TestSuites.SourceCode) -or ($null -ne $settings.TestSuites.PSModule) -or ($null -ne $settings.TestSuites.Module)
546553
)

0 commit comments

Comments
 (0)