Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions scripts/Resolve-PSModuleVersion.Helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -222,30 +222,29 @@ function Resolve-ReleaseDecision {
$shouldPublish = $false
}

# Defaults: always produce a prerelease patch version.
$majorRelease = $false
$minorRelease = $false
$patchRelease = $true
$hasVersionBump = $true
if (-not $shouldPublish) {
$createPrerelease = $true
# Always evaluate the version-bump labels so the resolved version reflects what WOULD be
# created, regardless of whether this run publishes. ReleaseType (and the prerelease label
# that drives it) only controls whether and how we publish - never the version increment.
$majorRelease = ($labels | Where-Object { $Configuration.MajorLabels -contains $_ }).Count -gt 0
$minorRelease = ($labels | Where-Object { $Configuration.MinorLabels -contains $_ }).Count -gt 0 -and -not $majorRelease
$patchRelease = (
(($labels | Where-Object { $Configuration.PatchLabels -contains $_ }).Count -gt 0) -or $Configuration.AutoPatching
) -and -not $majorRelease -and -not $minorRelease

$hasVersionBump = $majorRelease -or $minorRelease -or $patchRelease
if (-not $hasVersionBump) {
# No explicit bump label and no AutoPatching: still resolve a patch version so the run
# can preview what it would create, but do not publish a full release for an unlabeled change.
Write-Host 'No version bump label and AutoPatching disabled; previewing a patch version without publishing.'
$patchRelease = $true
$hasVersionBump = $true
$shouldPublish = $false
}

if ($shouldPublish) {
$majorRelease = ($labels | Where-Object { $Configuration.MajorLabels -contains $_ }).Count -gt 0
$minorRelease = ($labels | Where-Object { $Configuration.MinorLabels -contains $_ }).Count -gt 0 -and -not $majorRelease
$patchRelease = (
(($labels | Where-Object { $Configuration.PatchLabels -contains $_ }).Count -gt 0) -or $Configuration.AutoPatching
) -and -not $majorRelease -and -not $minorRelease

$hasVersionBump = $majorRelease -or $minorRelease -or $patchRelease
if (-not $hasVersionBump) {
Write-Host 'No version bump label found and AutoPatching is disabled. No release will be created.'
$shouldPublish = $false
$createPrerelease = $true
$patchRelease = $true
$hasVersionBump = $true
}
# Anything that is not a published full release is surfaced as a prerelease - either a
# published prerelease (ShouldPublish) or a non-published preview.
if (-not $shouldPublish) {
$createPrerelease = $true
}

Write-Host '-------------------------------------------------'
Expand Down
64 changes: 64 additions & 0 deletions tests/Resolve-PSModuleVersion.Helpers.Tests.Data.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,40 @@
PrereleaseName = 'feattestnone'
}
}
@{
Name = 'ReleaseType None with a minor label previews a minor bump'
ReleaseType = 'None'
AutoPatching = $false
HeadRef = 'feat/none-minor'
Labels = @('minor')
Expected = @{
ShouldPublish = $false
CreateRelease = $false
CreatePrerelease = $true
MajorRelease = $false
MinorRelease = $true
PatchRelease = $false
HasVersionBump = $true
PrereleaseName = 'featnoneminor'
}
}
@{
Name = 'ReleaseType None with a major label previews a major bump'
ReleaseType = 'None'
AutoPatching = $false
HeadRef = 'feat/none-major'
Labels = @('major')
Expected = @{
ShouldPublish = $false
CreateRelease = $false
CreatePrerelease = $true
MajorRelease = $true
MinorRelease = $false
PatchRelease = $false
HasVersionBump = $true
PrereleaseName = 'featnonemajor'
}
}
@{
Name = 'ReleaseType Prerelease with minor label'
ReleaseType = 'Prerelease'
Expand Down Expand Up @@ -412,6 +446,36 @@
ExpectedPrerelease = 'feattestnone001'
ExpectedFullVersion = 'v1.0.2-feattestnone001'
}
@{
Name = 'ReleaseType None with a minor label previews a minor prerelease'
LatestVersion = '1.0.1'
ReleaseType = 'None'
AutoPatching = $false
IncrementalPrerelease = $false
VersionPrefix = 'v'
HeadRef = 'feat/none-minor'
Labels = @('minor')
ExpectedShouldPublish = $false
ExpectedReleaseType = 'None'
ExpectedVersion = '1.1.0'
ExpectedPrerelease = 'featnoneminor001'
ExpectedFullVersion = 'v1.1.0-featnoneminor001'
}
Comment thread
MariusStorhaug marked this conversation as resolved.
@{
Name = 'ReleaseType None with a major label previews a major prerelease'
LatestVersion = '1.0.1'
ReleaseType = 'None'
AutoPatching = $false
IncrementalPrerelease = $false
VersionPrefix = 'v'
HeadRef = 'feat/none-major'
Labels = @('major')
ExpectedShouldPublish = $false
ExpectedReleaseType = 'None'
ExpectedVersion = '2.0.0'
ExpectedPrerelease = 'featnonemajor001'
ExpectedFullVersion = 'v2.0.0-featnonemajor001'
}
@{
Name = 'Prerelease type with incremental counter'
LatestVersion = '1.0.1'
Expand Down
Loading