From 30ddc0a8b50726abb5b0f93edf1f27b213c55937 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 27 Mar 2026 21:50:55 +0100 Subject: [PATCH] Skip BeforeAll/AfterAll-ModuleLocal when setup/teardown scripts do not exist --- src/main.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.ps1 b/src/main.ps1 index 7399f35..d037273 100644 --- a/src/main.ps1 +++ b/src/main.ps1 @@ -531,6 +531,13 @@ LogGroup 'Calculate Job Run Conditions:' { # Note: $shouldPrerelease already requires $hasImportantChanges, so no separate check needed. $shouldRunBuildTest = $isNotAbandonedPR -and $hasImportantChanges + # Check if setup/teardown scripts exist in the repository + $hasBeforeAllScript = Test-Path -Path 'tests/BeforeAll.ps1' + $hasAfterAllScript = Test-Path -Path 'tests/AfterAll.ps1' + Write-Host "Setup/teardown script detection:" + Write-Host " tests/BeforeAll.ps1 exists: $hasBeforeAllScript" + Write-Host " tests/AfterAll.ps1 exists: $hasAfterAllScript" + # Create Run object with all job-specific conditions $run = [pscustomobject]@{ LintRepository = $isOpenOrUpdatedPR -and (-not $settings.Linter.Skip) @@ -538,9 +545,9 @@ LogGroup 'Calculate Job Run Conditions:' { TestSourceCode = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.SourceCode) LintSourceCode = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.SourceCode) TestModule = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.PSModule) - BeforeAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) + BeforeAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasBeforeAllScript TestModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) - AfterAllModuleLocal = $true # Always runs if Test-ModuleLocal was not skipped + AfterAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasAfterAllScript GetTestResults = $shouldRunBuildTest -and (-not $settings.Test.TestResults.Skip) -and ( ($null -ne $settings.TestSuites.SourceCode) -or ($null -ne $settings.TestSuites.PSModule) -or ($null -ne $settings.TestSuites.Module) )