Skip to content

Commit 8d1dac7

Browse files
🪲 [Fix]: Version previews reflect the version-bump label regardless of release type (#9)
Version-bump labels (`major`, `minor`, `patch`) are now always evaluated when resolving a module version, so the version a run reports always matches what those labels would produce. Previously, on `pull_request` events (`ReleaseType = None`) the resolver ignored the labels and always previewed a **patch** prerelease, which made pull request previews misleading. `ReleaseType` — and the `prerelease` label that drives it — now only controls **whether and how** a version is published, never the size of the version increment. - Part of PSModule/Process-PSModule#378 ## Fixed: Pull request previews now reflect the version-bump label The resolved version on a non-publishing run now reflects the bump label instead of always showing a patch. Publishing behavior is unchanged — only the previewed version changes for label combinations that were previously never evaluated. | Situation | Before | After | |---|---|---| | Open PR, `minor` label, no `prerelease` label | `x.y.z+1` patch preview | **`x.(y+1).0` minor preview** (still not published) | | Open PR, `major` label, no `prerelease` label | `x.y.z+1` patch preview | **`(x+1).0.0` major preview** (still not published) | | PR with `prerelease` label | publishes a prerelease | unchanged — `prerelease` still gates publishing | | Merge to `main` with `minor` label | minor release | unchanged | ## Technical Details - `scripts/Resolve-PSModuleVersion.Helpers.psm1` (`Resolve-ReleaseDecision`): the `major`/`minor`/`patch` label evaluation was moved out from behind the `if ($shouldPublish)` guard so it always runs. When no bump label is present and `AutoPatching` is disabled, the run still previews a patch version but sets `ShouldPublish = $false`. Any run that is not a published full release continues to be surfaced as a prerelease (`CreatePrerelease = $true`). - `tests/Resolve-PSModuleVersion.Helpers.Tests.Data.psd1`: added `ReleaseDecision` and `EndToEnd` cases for `None + minor` and `None + major` previews. All existing `ReleaseDecision`, `EndToEnd`, and `NextModuleVersion` cases are unchanged. - Validation: 157/157 Pester tests pass; PSScriptAnalyzer clean. - E2E: `MariusStorhaug/MariusTestModule` PR #34 (labelled `Minor`, no `prerelease` label) now previews `v0.5.0-teste2eimporttestdata001` with `ShouldPublish = False` (previously `v0.4.2-…`). - Relates to `PSModule/Process-PSModule#378`.
1 parent bc63f07 commit 8d1dac7

2 files changed

Lines changed: 85 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: 64 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,36 @@
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+
}
464+
@{
465+
Name = 'ReleaseType None with a major label previews a major prerelease'
466+
LatestVersion = '1.0.1'
467+
ReleaseType = 'None'
468+
AutoPatching = $false
469+
IncrementalPrerelease = $false
470+
VersionPrefix = 'v'
471+
HeadRef = 'feat/none-major'
472+
Labels = @('major')
473+
ExpectedShouldPublish = $false
474+
ExpectedReleaseType = 'None'
475+
ExpectedVersion = '2.0.0'
476+
ExpectedPrerelease = 'featnonemajor001'
477+
ExpectedFullVersion = 'v2.0.0-featnonemajor001'
478+
}
415479
@{
416480
Name = 'Prerelease type with incremental counter'
417481
LatestVersion = '1.0.1'

0 commit comments

Comments
 (0)