Skip to content

Commit ebf5be5

Browse files
Validate effective default bumps and release intent across preview and skip routes
1 parent da60cf9 commit ebf5be5

9 files changed

Lines changed: 260 additions & 43 deletions

File tree

‎.github/actions/Get-PSModuleSettings/src/Get-PSModuleSettings.Helpers.psm1‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function Resolve-WorkflowEventRouting {
4343
$isClosedPR = $isPR -and $EventAction -eq 'closed'
4444
$isAbandonedPR = $isClosedPR -and -not $PullRequestIsMerged
4545
$isMergedPR = $isClosedPR -and $PullRequestIsMerged
46-
$shouldPrerelease = $isOpenOrLabeledPR -and $HasPrereleaseLabel -and $HasImportantChanges
46+
$shouldPrerelease = $isOpenOrUpdatedPR -and $HasPrereleaseLabel -and $HasImportantChanges
4747
$shouldRelease = (
4848
($IsPushToDefaultBranch -or $IsManualDispatchToDefaultBranch) -and
4949
$HasImportantChanges
@@ -86,8 +86,9 @@ function Resolve-PSModulePublishSetting {
8686
8787
.DESCRIPTION
8888
Applies Process-PSModule defaults while preserving every consumer-provided
89-
publication and release-label mapping. Rejects the removed AutoPatching
90-
setting and invalid DefaultBump values with migration guidance.
89+
publication and release-label mapping. Rejects the removed AutoPatching,
90+
unknown settings, and invalid DefaultBump values. Records the default's
91+
source for the downstream release decision.
9192
9293
.OUTPUTS
9394
System.Management.Automation.PSCustomObject
@@ -132,7 +133,7 @@ function Resolve-PSModulePublishSetting {
132133
)
133134
}
134135

135-
[pscustomobject]@{
136+
$resolved = [pscustomobject]@{
136137
Skip = $PublishModule.Skip ?? $false
137138
AutoCleanup = $PublishModule.AutoCleanup ?? $true
138139
DefaultBump = $defaultBump
@@ -148,6 +149,15 @@ function Resolve-PSModulePublishSetting {
148149
UsePRBodyAsReleaseNotes = $PublishModule.UsePRBodyAsReleaseNotes ?? $true
149150
UsePRTitleAsNotesHeading = $PublishModule.UsePRTitleAsNotesHeading ?? $true
150151
}
152+
153+
$allowedProperties = @($resolved.PSObject.Properties.Name) + 'ReleaseType'
154+
$unknownProperties = @($propertyNames | Where-Object { $_ -notin $allowedProperties })
155+
if ($unknownProperties.Count -gt 0) {
156+
throw "Publish.Module contains unsupported settings: [$($unknownProperties -join ', ')]."
157+
}
158+
$source = if ($hasDefaultBump) { 'Publish.Module.DefaultBump' } else { 'SharedDefault' }
159+
$resolved | Add-Member -NotePropertyName DefaultBumpSource -NotePropertyValue $source
160+
$resolved
151161
}
152162

153163
function Select-PullRequestForPush {
@@ -189,11 +199,11 @@ function Get-DiscardedReleasePullRequest {
189199
Select-PullRequestForPush returns nothing both when a commit has no associated pull request
190200
and when every associated pull request fails its criteria. Only the first case is safe: a
191201
commit pushed directly to the default branch has no label to honour, so the direct-release
192-
path applies the default patch bump.
202+
path applies the effective DefaultBump.
193203
194204
The unsafe case is a pull request that was merged into the default branch, and therefore
195205
carries the version label that was meant to drive the release, but was not selected because
196-
its merge commit does not match the commit being released. Falling back to a patch bump
206+
its merge commit does not match the commit being released. Falling back to DefaultBump
197207
there publishes a version nobody asked for, and a PowerShell Gallery version cannot be
198208
reclaimed, so the caller must fail instead.
199209
@@ -249,9 +259,9 @@ function Resolve-ReleasePullRequest {
249259
that merge is still the tip. Rerun the original workflow's failed jobs for an older commit.
250260
251261
When no pull request is selected, the outcome depends on why. A commit pushed directly to
252-
the default branch has no label to honour, so the release proceeds with the default patch
253-
bump. A commit associated with a merged default-branch pull request that does not match it
254-
does carry a label, and applying a patch bump would publish a version nobody asked for.
262+
the default branch has no label to honor, so the release proceeds with the effective
263+
DefaultBump. A commit associated with a merged default-branch pull request that does not
264+
match it carries a label, and applying a default would discard that release intent.
255265
That case throws for an important default-branch push or a recovery dispatch, but not for a
256266
documentation-only push that cannot publish.
257267
@@ -336,7 +346,7 @@ function Resolve-ReleasePullRequest {
336346
"Commit [$CommitSha] cannot be released because its version label cannot be determined. " +
337347
'The following merged pull request(s) are associated with it but none matches the commit ' +
338348
"being released: $($discarded -join '; '). " +
339-
'Refusing to fall back to a patch bump, because a wrong version published to the ' +
349+
'Refusing to discard the release intent and apply DefaultBump, because a wrong version published to the ' +
340350
'PowerShell Gallery cannot be reclaimed. Rerun the original workflow for the intended merge commit. ' +
341351
'A default-branch dispatch can recover that commit only while it is still the branch tip.'
342352
)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@
129129
"Module": {
130130
"type": "object",
131131
"description": "Module publish configuration",
132+
"not": {
133+
"required": [
134+
"AutoPatching"
135+
]
136+
},
132137
"properties": {
133138
"Skip": {
134139
"type": "boolean",

‎.github/actions/Get-PSModuleSettings/tests/Get-PSModuleSettings.Helpers.Tests.ps1‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ Describe 'Resolve-WorkflowEventRouting' {
8080
$result.ShouldCleanupEvent | Should -BeFalse
8181
$result.ShouldRunCleanup | Should -BeFalse
8282
}
83+
84+
It 'retains prerelease mode when an explicit bump label is removed' {
85+
$parameters = @{
86+
EventName = 'pull_request'
87+
EventAction = 'unlabeled'
88+
IsTargetDefaultBranch = $true
89+
HasImportantChanges = $true
90+
HasPrereleaseLabel = $true
91+
}
92+
93+
$result = Resolve-WorkflowEventRouting @parameters
94+
95+
$result.ReleaseType | Should -Be 'Prerelease'
96+
$result.ShouldRunBuildTest | Should -BeTrue
97+
}
98+
99+
It 'stops prerelease publication when its mode label is removed' {
100+
$result = Resolve-WorkflowEventRouting -EventName pull_request -EventAction unlabeled `
101+
-HasImportantChanges $true -HasPrereleaseLabel $false
102+
103+
$result.ReleaseType | Should -Be 'None'
104+
$result.ShouldRunBuildTest | Should -BeTrue
105+
}
83106
}
84107

85108
Describe 'Resolve-PSModulePublishSetting' {
@@ -147,6 +170,32 @@ Describe 'Resolve-PSModulePublishSetting' {
147170
{ Resolve-PSModulePublishSetting -PublishModule $publishModule } |
148171
Should -Throw '*AutoPatching was removed*Replace it with Publish.Module.DefaultBump*'
149172
}
173+
174+
It 'rejects unknown publication settings rather than masking them with a valid default' {
175+
$publishModule = [pscustomobject]@{ DefaultBump = 'major'; DefautBump = 'minor' }
176+
177+
{ Resolve-PSModulePublishSetting -PublishModule $publishModule } |
178+
Should -Throw '*unsupported*DefautBump*'
179+
}
180+
181+
It 'records whether the shared default or settings supplied the bump' {
182+
$shared = Resolve-PSModulePublishSetting -PublishModule $null
183+
$configured = Resolve-PSModulePublishSetting -PublishModule ([pscustomobject]@{ DefaultBump = 'minor' })
184+
185+
$shared.DefaultBumpSource | Should -BeExactly 'SharedDefault'
186+
$configured.DefaultBumpSource | Should -BeExactly 'Publish.Module.DefaultBump'
187+
}
188+
189+
It 'rejects removed AutoPatching in the actual schema with <AutoPatching>' -ForEach @(
190+
@{ AutoPatching = $true }
191+
@{ AutoPatching = $false }
192+
) {
193+
$schemaPath = Join-Path -Path $PSScriptRoot -ChildPath '../src/Settings.schema.json'
194+
$json = @{ Publish = @{ Module = @{ DefaultBump = 'patch'; AutoPatching = $AutoPatching } } } |
195+
ConvertTo-Json -Depth 5
196+
197+
Test-Json -Json $json -SchemaFile $schemaPath -ErrorAction Stop | Should -BeFalse
198+
}
150199
}
151200

152201
Describe 'Select-PullRequestForPush' {

0 commit comments

Comments
 (0)