Skip to content

Commit a862b80

Browse files
Always evaluate version-bump labels regardless of ReleaseType
The major/minor/patch label evaluation was gated behind ShouldPublish, so on a pull_request event (ReleaseType None) the resolver ignored the labels and always previewed a patch prerelease. Now the bump labels are always evaluated, so the resolved version reflects what WOULD be created; ReleaseType (and the prerelease label that drives it) only controls whether and how we publish. Adds ReleaseDecision + EndToEnd tests for None + minor/major previews. All existing cases are unchanged (152/152 pass).
1 parent bc63f07 commit a862b80

2 files changed

Lines changed: 70 additions & 22 deletions

File tree

scripts/Resolve-PSModuleVersion.Helpers.psm1

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -222,30 +222,29 @@ function Resolve-ReleaseDecision {
222222
$shouldPublish = $false
223223
}
224224

225-
# Defaults: always produce a prerelease patch version.
226-
$majorRelease = $false
227-
$minorRelease = $false
228-
$patchRelease = $true
229-
$hasVersionBump = $true
230-
if (-not $shouldPublish) {
231-
$createPrerelease = $true
225+
# Always evaluate the version-bump labels so the resolved version reflects what WOULD be
226+
# created, regardless of whether this run publishes. ReleaseType (and the prerelease label
227+
# that drives it) only controls whether and how we publish - never the version increment.
228+
$majorRelease = ($labels | Where-Object { $Configuration.MajorLabels -contains $_ }).Count -gt 0
229+
$minorRelease = ($labels | Where-Object { $Configuration.MinorLabels -contains $_ }).Count -gt 0 -and -not $majorRelease
230+
$patchRelease = (
231+
(($labels | Where-Object { $Configuration.PatchLabels -contains $_ }).Count -gt 0) -or $Configuration.AutoPatching
232+
) -and -not $majorRelease -and -not $minorRelease
233+
234+
$hasVersionBump = $majorRelease -or $minorRelease -or $patchRelease
235+
if (-not $hasVersionBump) {
236+
# No explicit bump label and no AutoPatching: still resolve a patch version so the run
237+
# can preview what it would create, but do not publish a full release for an unlabeled change.
238+
Write-Host 'No version bump label and AutoPatching disabled; previewing a patch version without publishing.'
239+
$patchRelease = $true
240+
$hasVersionBump = $true
241+
$shouldPublish = $false
232242
}
233243

234-
if ($shouldPublish) {
235-
$majorRelease = ($labels | Where-Object { $Configuration.MajorLabels -contains $_ }).Count -gt 0
236-
$minorRelease = ($labels | Where-Object { $Configuration.MinorLabels -contains $_ }).Count -gt 0 -and -not $majorRelease
237-
$patchRelease = (
238-
(($labels | Where-Object { $Configuration.PatchLabels -contains $_ }).Count -gt 0) -or $Configuration.AutoPatching
239-
) -and -not $majorRelease -and -not $minorRelease
240-
241-
$hasVersionBump = $majorRelease -or $minorRelease -or $patchRelease
242-
if (-not $hasVersionBump) {
243-
Write-Host 'No version bump label found and AutoPatching is disabled. No release will be created.'
244-
$shouldPublish = $false
245-
$createPrerelease = $true
246-
$patchRelease = $true
247-
$hasVersionBump = $true
248-
}
244+
# Anything that is not a published full release is surfaced as a prerelease - either a
245+
# published prerelease (ShouldPublish) or a non-published preview.
246+
if (-not $shouldPublish) {
247+
$createPrerelease = $true
249248
}
250249

251250
Write-Host '-------------------------------------------------'

tests/Resolve-PSModuleVersion.Helpers.Tests.Data.psd1

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,40 @@
102102
PrereleaseName = 'feattestnone'
103103
}
104104
}
105+
@{
106+
Name = 'ReleaseType None with a minor label previews a minor bump'
107+
ReleaseType = 'None'
108+
AutoPatching = $false
109+
HeadRef = 'feat/none-minor'
110+
Labels = @('minor')
111+
Expected = @{
112+
ShouldPublish = $false
113+
CreateRelease = $false
114+
CreatePrerelease = $true
115+
MajorRelease = $false
116+
MinorRelease = $true
117+
PatchRelease = $false
118+
HasVersionBump = $true
119+
PrereleaseName = 'featnoneminor'
120+
}
121+
}
122+
@{
123+
Name = 'ReleaseType None with a major label previews a major bump'
124+
ReleaseType = 'None'
125+
AutoPatching = $false
126+
HeadRef = 'feat/none-major'
127+
Labels = @('major')
128+
Expected = @{
129+
ShouldPublish = $false
130+
CreateRelease = $false
131+
CreatePrerelease = $true
132+
MajorRelease = $true
133+
MinorRelease = $false
134+
PatchRelease = $false
135+
HasVersionBump = $true
136+
PrereleaseName = 'featnonemajor'
137+
}
138+
}
105139
@{
106140
Name = 'ReleaseType Prerelease with minor label'
107141
ReleaseType = 'Prerelease'
@@ -412,6 +446,21 @@
412446
ExpectedPrerelease = 'feattestnone001'
413447
ExpectedFullVersion = 'v1.0.2-feattestnone001'
414448
}
449+
@{
450+
Name = 'ReleaseType None with a minor label previews a minor prerelease'
451+
LatestVersion = '1.0.1'
452+
ReleaseType = 'None'
453+
AutoPatching = $false
454+
IncrementalPrerelease = $false
455+
VersionPrefix = 'v'
456+
HeadRef = 'feat/none-minor'
457+
Labels = @('minor')
458+
ExpectedShouldPublish = $false
459+
ExpectedReleaseType = 'None'
460+
ExpectedVersion = '1.1.0'
461+
ExpectedPrerelease = 'featnoneminor001'
462+
ExpectedFullVersion = 'v1.1.0-featnoneminor001'
463+
}
415464
@{
416465
Name = 'Prerelease type with incremental counter'
417466
LatestVersion = '1.0.1'

0 commit comments

Comments
 (0)