Skip to content

Commit 5998e39

Browse files
⚙️ [Maintenance]: Internalize runtime settings by phase (#402)
Runtime execution flags and test matrices are now owned by each phase object instead of a shared root `Run`/`TestSuites` contract. ## Changed: Runtime execution state is phase-owned `Get-PSModuleSettings` now enriches each phase with `Desired`/`Enabled` state and stores suites under the owning test phase: - `Linter.Repository` / `Linter.SourceCode` - `Build.Module` / `Build.Docs` / `Build.Site` - `Test.SourceCode.Suites`, `Test.PSModule.Suites`, `Test.Module.Suites` - `Test.Module.BeforeAllEnabled`, `Test.Module.MainEnabled`, `Test.Module.AfterAllEnabled` - `Test.TestResults.Enabled`, `Test.CodeCoverage.Enabled` - `Publish.Module.Enabled`, `Publish.Site.Enabled` ## Changed: Workflows now consume the new phase-owned schema Reusable workflows and the root workflow were updated to reference phase-local state instead of `Settings.Run.*` and `Settings.TestSuites.*`. ## Changed: Version resolution is scoped under publish phase `Plan.yml` now stores resolved version metadata under: - `Settings.Publish.Module.Resolution.Version` - `Settings.Publish.Module.Resolution.Prerelease` - `Settings.Publish.Module.Resolution.FullVersion` - `Settings.Publish.Module.Resolution.ReleaseType` - `Settings.Publish.Module.Resolution.CreateRelease` `Build-Module.yml` and `Test-ModuleLocal.yml` were updated to read this new location. ## Changed: Settings schema deprecates root Run contract `Settings.schema.json` no longer defines root `TestSuites` and marks root `Run` as deprecated. ## Technical Details - Preserved existing behavior by deriving phase `Enabled` values from the same event/state logic previously used to build `Run.*`. - Kept the input settings shape stable for repository owners; this refactor targets the internal enriched settings object passed between workflow jobs. <details> <summary>Related issues</summary> - Opened directly from maintainer request (no linked issue). </details> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 7ad7d26 commit 5998e39

10 files changed

Lines changed: 104 additions & 168 deletions

File tree

.github/actions/Get-PSModuleSettings/src/Settings.schema.json

Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -220,51 +220,6 @@
220220
}
221221
}
222222
},
223-
"TestSuites": {
224-
"type": "object",
225-
"description": "Test suite configurations",
226-
"properties": {
227-
"SourceCode": {
228-
"oneOf": [
229-
{
230-
"type": "null"
231-
},
232-
{
233-
"type": "array",
234-
"items": {
235-
"$ref": "#/definitions/testSuite"
236-
}
237-
}
238-
]
239-
},
240-
"PSModule": {
241-
"oneOf": [
242-
{
243-
"type": "null"
244-
},
245-
{
246-
"type": "array",
247-
"items": {
248-
"$ref": "#/definitions/testSuite"
249-
}
250-
}
251-
]
252-
},
253-
"Module": {
254-
"oneOf": [
255-
{
256-
"type": "null"
257-
},
258-
{
259-
"type": "array",
260-
"items": {
261-
"$ref": "#/definitions/moduleTestSuite"
262-
}
263-
}
264-
]
265-
}
266-
}
267-
},
268223
"SettingsPath": {
269224
"type": "string",
270225
"description": "Path to the settings file"
@@ -306,66 +261,8 @@
306261
"description": "Indicates if important files have changed in the PR (src/**, examples/**, README.md, .github/workflows/Process-PSModule.yml)"
307262
},
308263
"Run": {
309-
"type": "object",
310-
"description": "Runtime execution flags",
311-
"properties": {
312-
"LintRepository": {
313-
"type": "boolean",
314-
"description": "Run repository linting"
315-
},
316-
"BuildModule": {
317-
"type": "boolean",
318-
"description": "Build the module"
319-
},
320-
"TestSourceCode": {
321-
"type": "boolean",
322-
"description": "Test source code"
323-
},
324-
"LintSourceCode": {
325-
"type": "boolean",
326-
"description": "Lint source code"
327-
},
328-
"TestModule": {
329-
"type": "boolean",
330-
"description": "Test the module"
331-
},
332-
"BeforeAllModuleLocal": {
333-
"type": "boolean",
334-
"description": "Run before all module local tests"
335-
},
336-
"TestModuleLocal": {
337-
"type": "boolean",
338-
"description": "Test module locally"
339-
},
340-
"AfterAllModuleLocal": {
341-
"type": "boolean",
342-
"description": "Run after all module local tests"
343-
},
344-
"GetTestResults": {
345-
"type": "boolean",
346-
"description": "Collect test results"
347-
},
348-
"GetCodeCoverage": {
349-
"type": "boolean",
350-
"description": "Collect code coverage"
351-
},
352-
"PublishModule": {
353-
"type": "boolean",
354-
"description": "Publish the module"
355-
},
356-
"BuildDocs": {
357-
"type": "boolean",
358-
"description": "Build documentation"
359-
},
360-
"BuildSite": {
361-
"type": "boolean",
362-
"description": "Build the site"
363-
},
364-
"PublishSite": {
365-
"type": "boolean",
366-
"description": "Publish the site"
367-
}
368-
}
264+
"type": "null",
265+
"description": "Deprecated. Runtime execution flags are now stored on each phase object."
369266
}
370267
},
371268
"definitions": {

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

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,6 @@ if ($settings.Test.Skip) {
375375
$sourceCodeTestSuites = $null
376376
$psModuleTestSuites = $null
377377
$moduleTestSuites = $null
378-
379-
# Add TestSuites to settings
380-
$settings | Add-Member -MemberType NoteProperty -Name TestSuites -Value ([pscustomobject]@{
381-
SourceCode = $null
382-
PSModule = $null
383-
Module = $null
384-
})
385378
} else {
386379

387380
# Define test configurations as an array of hashtables.
@@ -529,14 +522,13 @@ if ($settings.Test.Skip) {
529522
$moduleTestSuites | Format-Table -AutoSize | Out-String
530523
}
531524

532-
# Add TestSuites to settings
533-
$settings | Add-Member -MemberType NoteProperty -Name TestSuites -Value ([pscustomobject]@{
534-
SourceCode = $sourceCodeTestSuites
535-
PSModule = $psModuleTestSuites
536-
Module = $moduleTestSuites
537-
})
538525
}
539526

527+
# Keep test suites with each test phase that owns them.
528+
$settings.Test.SourceCode | Add-Member -MemberType NoteProperty -Name Suites -Value $sourceCodeTestSuites -Force
529+
$settings.Test.PSModule | Add-Member -MemberType NoteProperty -Name Suites -Value $psModuleTestSuites -Force
530+
$settings.Test.Module | Add-Member -MemberType NoteProperty -Name Suites -Value $moduleTestSuites -Force
531+
540532
# Calculate job-specific conditions and add to settings
541533
LogGroup 'Calculate Job Run Conditions:' {
542534
# Calculate if prereleases should be cleaned up:
@@ -565,32 +557,79 @@ LogGroup 'Calculate Job Run Conditions:' {
565557
Write-Host " tests/BeforeAll.ps1 exists: $hasBeforeAllScript"
566558
Write-Host " tests/AfterAll.ps1 exists: $hasAfterAllScript"
567559

568-
# Create Run object with all job-specific conditions
569-
$run = [pscustomobject]@{
570-
LintRepository = $isOpenOrUpdatedPR -and (-not $settings.Linter.Skip)
571-
BuildModule = $shouldRunBuildTest -and (-not $settings.Build.Module.Skip)
572-
TestSourceCode = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.SourceCode)
573-
LintSourceCode = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.SourceCode)
574-
TestModule = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.PSModule)
575-
BeforeAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasBeforeAllScript
576-
TestModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module)
577-
AfterAllModuleLocal = $shouldRunBuildTest -and ($null -ne $settings.TestSuites.Module) -and $hasAfterAllScript
578-
GetTestResults = $shouldRunBuildTest -and (-not $settings.Test.TestResults.Skip) -and (
579-
($null -ne $settings.TestSuites.SourceCode) -or ($null -ne $settings.TestSuites.PSModule) -or ($null -ne $settings.TestSuites.Module)
560+
$sourceCodeEnabled = $shouldRunBuildTest -and ($null -ne $settings.Test.SourceCode.Suites)
561+
$psModuleEnabled = $shouldRunBuildTest -and ($null -ne $settings.Test.PSModule.Suites)
562+
$moduleLocalEnabled = $shouldRunBuildTest -and ($null -ne $settings.Test.Module.Suites)
563+
$beforeAllEnabled = $moduleLocalEnabled -and $hasBeforeAllScript
564+
$afterAllEnabled = $moduleLocalEnabled -and $hasAfterAllScript
565+
566+
# Keep desired/computed execution state with each phase.
567+
$settings.Linter | Add-Member -MemberType NoteProperty -Name Repository -Value ([pscustomobject]@{
568+
Desired = -not $settings.Linter.Skip
569+
Enabled = $isOpenOrUpdatedPR -and (-not $settings.Linter.Skip)
570+
}) -Force
571+
$settings.Linter | Add-Member -MemberType NoteProperty -Name SourceCode -Value ([pscustomobject]@{
572+
Desired = -not $settings.Test.SourceCode.Skip
573+
Enabled = $sourceCodeEnabled
574+
}) -Force
575+
576+
$settings.Build.Module | Add-Member -MemberType NoteProperty -Name Desired -Value (-not $settings.Build.Module.Skip) -Force
577+
$settings.Build.Module | Add-Member -MemberType NoteProperty -Name Enabled -Value (
578+
$shouldRunBuildTest -and (-not $settings.Build.Module.Skip)
579+
) -Force
580+
$settings.Build.Docs | Add-Member -MemberType NoteProperty -Name Desired -Value (-not $settings.Build.Docs.Skip) -Force
581+
$settings.Build.Docs | Add-Member -MemberType NoteProperty -Name Enabled -Value ($shouldRunBuildTest -and (-not $settings.Build.Docs.Skip)) -Force
582+
$settings.Build.Site | Add-Member -MemberType NoteProperty -Name Desired -Value (-not $settings.Build.Site.Skip) -Force
583+
$settings.Build.Site | Add-Member -MemberType NoteProperty -Name Enabled -Value ($shouldRunBuildTest -and (-not $settings.Build.Site.Skip)) -Force
584+
585+
$settings.Test.SourceCode | Add-Member -MemberType NoteProperty -Name Desired -Value (-not $settings.Test.SourceCode.Skip) -Force
586+
$settings.Test.SourceCode | Add-Member -MemberType NoteProperty -Name Enabled -Value $sourceCodeEnabled -Force
587+
$settings.Test.PSModule | Add-Member -MemberType NoteProperty -Name Desired -Value (-not $settings.Test.PSModule.Skip) -Force
588+
$settings.Test.PSModule | Add-Member -MemberType NoteProperty -Name Enabled -Value $psModuleEnabled -Force
589+
$settings.Test.Module | Add-Member -MemberType NoteProperty -Name Desired -Value (-not $settings.Test.Module.Skip) -Force
590+
$settings.Test.Module | Add-Member -MemberType NoteProperty -Name BeforeAllEnabled -Value $beforeAllEnabled -Force
591+
$settings.Test.Module | Add-Member -MemberType NoteProperty -Name MainEnabled -Value $moduleLocalEnabled -Force
592+
$settings.Test.Module | Add-Member -MemberType NoteProperty -Name AfterAllEnabled -Value $afterAllEnabled -Force
593+
594+
$settings.Test.TestResults | Add-Member -MemberType NoteProperty -Name Desired -Value (-not $settings.Test.TestResults.Skip) -Force
595+
$settings.Test.TestResults | Add-Member -MemberType NoteProperty -Name Enabled -Value (
596+
$shouldRunBuildTest -and (-not $settings.Test.TestResults.Skip) -and (
597+
($null -ne $settings.Test.SourceCode.Suites) -or ($null -ne $settings.Test.PSModule.Suites) -or ($null -ne $settings.Test.Module.Suites)
580598
)
581-
GetCodeCoverage = $shouldRunBuildTest -and (-not $settings.Test.CodeCoverage.Skip) -and (
582-
($null -ne $settings.TestSuites.PSModule) -or ($null -ne $settings.TestSuites.Module)
599+
) -Force
600+
$settings.Test.CodeCoverage | Add-Member -MemberType NoteProperty -Name Desired -Value (-not $settings.Test.CodeCoverage.Skip) -Force
601+
$settings.Test.CodeCoverage | Add-Member -MemberType NoteProperty -Name Enabled -Value (
602+
$shouldRunBuildTest -and (-not $settings.Test.CodeCoverage.Skip) -and (
603+
($null -ne $settings.Test.PSModule.Suites) -or ($null -ne $settings.Test.Module.Suites)
583604
)
584-
PublishModule = ($releaseType -ne 'None') -or $shouldAutoCleanup
585-
BuildDocs = $shouldRunBuildTest -and (-not $settings.Build.Docs.Skip)
586-
BuildSite = $shouldRunBuildTest -and (-not $settings.Build.Site.Skip)
587-
PublishSite = $isMergedPR -and $isTargetDefaultBranch -and $hasImportantChanges
588-
}
589-
$settings | Add-Member -MemberType NoteProperty -Name Run -Value $run
605+
) -Force
606+
607+
$settings.Publish.Module | Add-Member -MemberType NoteProperty -Name Desired -Value (($releaseType -ne 'None') -or $shouldAutoCleanup) -Force
608+
$settings.Publish.Module | Add-Member -MemberType NoteProperty -Name Enabled -Value (($releaseType -ne 'None') -or $shouldAutoCleanup) -Force
609+
$settings.Publish | Add-Member -MemberType NoteProperty -Name Site -Value ([pscustomobject]@{
610+
Desired = $isMergedPR -and $isTargetDefaultBranch -and $hasImportantChanges
611+
Enabled = $isMergedPR -and $isTargetDefaultBranch -and $hasImportantChanges
612+
}) -Force
613+
590614
$settings | Add-Member -MemberType NoteProperty -Name HasImportantChanges -Value $hasImportantChanges
591615

592-
Write-Host 'Job Run Conditions:'
593-
$run | Format-List | Out-String
616+
Write-Host 'Phase execution state:'
617+
[pscustomobject]@{
618+
LintRepository = $settings.Linter.Repository.Enabled
619+
BuildModule = $settings.Build.Module.Enabled
620+
TestSourceCode = $settings.Test.SourceCode.Enabled
621+
LintSourceCode = $settings.Linter.SourceCode.Enabled
622+
TestModule = $settings.Test.PSModule.Enabled
623+
BeforeAllModuleLocal = $settings.Test.Module.BeforeAllEnabled
624+
TestModuleLocal = $settings.Test.Module.MainEnabled
625+
AfterAllModuleLocal = $settings.Test.Module.AfterAllEnabled
626+
GetTestResults = $settings.Test.TestResults.Enabled
627+
GetCodeCoverage = $settings.Test.CodeCoverage.Enabled
628+
PublishModule = $settings.Publish.Module.Enabled
629+
BuildDocs = $settings.Build.Docs.Enabled
630+
BuildSite = $settings.Build.Site.Enabled
631+
PublishSite = $settings.Publish.Site.Enabled
632+
} | Format-List | Out-String
594633
}
595634

596635
LogGroup 'Final settings' {

.github/workflows/Build-Module.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
uses: ./_wf/.github/actions/Build-PSModule
4242
with:
4343
Name: ${{ fromJson(inputs.Settings).Name }}
44-
Version: ${{ fromJson(inputs.Settings).Module.Version != '' && fromJson(inputs.Settings).Module.Version || '999.0.0' }}
45-
Prerelease: ${{ fromJson(inputs.Settings).Module.Prerelease }}
44+
Version: ${{ fromJson(inputs.Settings).Publish.Module.Resolution.Version != '' && fromJson(inputs.Settings).Publish.Module.Resolution.Version || '999.0.0' }}
45+
Prerelease: ${{ fromJson(inputs.Settings).Publish.Module.Resolution.Prerelease }}
4646
ArtifactName: ${{ inputs.ArtifactName }}
4747
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}

.github/workflows/Get-TestResults.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ jobs:
3333
uses: ./_wf/.github/actions/Get-PesterTestResults
3434
id: Get-TestResults
3535
with:
36-
SourceCodeTestSuites: ${{ toJSON(fromJson(inputs.Settings).TestSuites.SourceCode) }}
37-
PSModuleTestSuites: ${{ toJSON(fromJson(inputs.Settings).TestSuites.PSModule) }}
38-
ModuleTestSuites: ${{ toJSON(fromJson(inputs.Settings).TestSuites.Module) }}
36+
SourceCodeTestSuites: ${{ toJSON(fromJson(inputs.Settings).Test.SourceCode.Suites) }}
37+
PSModuleTestSuites: ${{ toJSON(fromJson(inputs.Settings).Test.PSModule.Suites) }}
38+
ModuleTestSuites: ${{ toJSON(fromJson(inputs.Settings).Test.Module.Suites) }}
3939
BeforeAllModuleLocalResult: ${{ inputs.BeforeAllModuleLocalResult }}
4040
Debug: ${{ fromJson(inputs.Settings).Debug }}
4141
Prerelease: ${{ fromJson(inputs.Settings).Prerelease }}

.github/workflows/Lint-SourceCode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
include: ${{ fromJson(inputs.Settings).TestSuites.SourceCode }}
21+
include: ${{ fromJson(inputs.Settings).Test.SourceCode.Suites }}
2222
steps:
2323
- name: Checkout Code
2424
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

.github/workflows/Plan.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Plan
44
# It runs two steps:
55
# 1. Get-PSModuleSettings - loads and resolves configuration
66
# 2. Resolve-PSModuleVersion - calculates the next version from settings + PR labels
7-
# The resolved version is merged into the Settings object (Settings.Module.*) by the Enrich-Settings step.
7+
# The resolved version is merged into the publish phase object (Settings.Publish.Module.Resolution.*) by the Enrich-Settings step.
88
# All downstream jobs receive one self-contained Settings JSON with no separate version outputs.
99

1010
on:
@@ -118,12 +118,12 @@ jobs:
118118
CREATE_RELEASE: ${{ steps.Resolve-Version.outputs.CreateRelease }}
119119
run: |
120120
$settings = $env:SETTINGS | ConvertFrom-Json
121-
$settings | Add-Member -MemberType NoteProperty -Name Module -Value ([pscustomobject]@{
121+
$settings.Publish.Module | Add-Member -MemberType NoteProperty -Name Resolution -Value ([pscustomobject]@{
122122
Version = $env:VERSION
123123
Prerelease = $env:PRERELEASE
124124
FullVersion = $env:FULL_VERSION
125125
ReleaseType = if ([string]::IsNullOrEmpty($env:RELEASE_TYPE)) { 'None' } else { $env:RELEASE_TYPE }
126126
CreateRelease = $env:CREATE_RELEASE -eq 'true'
127-
})
127+
}) -Force
128128
$enriched = $settings | ConvertTo-Json -Depth 10 -Compress
129129
"Settings=$enriched" >> $env:GITHUB_OUTPUT

.github/workflows/Test-Module.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
include: ${{ fromJson(inputs.Settings).TestSuites.PSModule }}
21+
include: ${{ fromJson(inputs.Settings).Test.PSModule.Suites }}
2222
steps:
2323
- name: Checkout repository
2424
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -56,7 +56,7 @@ jobs:
5656
strategy:
5757
fail-fast: false
5858
matrix:
59-
include: ${{ fromJson(inputs.Settings).TestSuites.PSModule }}
59+
include: ${{ fromJson(inputs.Settings).Test.PSModule.Suites }}
6060
steps:
6161
- name: Checkout repository
6262
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

.github/workflows/Test-ModuleLocal.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
strategy:
2929
fail-fast: false
3030
matrix:
31-
include: ${{ fromJson(inputs.Settings).TestSuites.Module }}
31+
include: ${{ fromJson(inputs.Settings).Test.Module.Suites }}
3232
steps:
3333
- name: Checkout Code
3434
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -88,4 +88,4 @@ jobs:
8888
WorkingDirectory: ${{ fromJson(inputs.Settings).WorkingDirectory }}
8989
Prescript: | # This is to speed up module loading in Pester.
9090
Install-PSResource -Repository PSGallery -TrustRepository -Name PSCustomObject
91-
Import-Module -Name '${{ steps.import-module.outputs.name }}' -RequiredVersion '${{ fromJson(inputs.Settings).Module.Version }}'
91+
Import-Module -Name '${{ steps.import-module.outputs.name }}' -RequiredVersion '${{ fromJson(inputs.Settings).Publish.Module.Resolution.Version }}'

.github/workflows/Test-SourceCode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
include: ${{ fromJson(inputs.Settings).TestSuites.SourceCode }}
21+
include: ${{ fromJson(inputs.Settings).Test.SourceCode.Suites }}
2222
steps:
2323
- name: Checkout Code
2424
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0

0 commit comments

Comments
 (0)