This commit is contained in:
Thomas
2026-03-12 23:41:12 +01:00
parent 8049c505a0
commit 7c1a20465a
10 changed files with 1057 additions and 120 deletions

View File

@@ -9,6 +9,25 @@ import (
"git.thokra.dev/thokra/stamp/internal/changeset"
)
// PreReleaseBump converts a regular bump type to its pre-release equivalent,
// taking into account whether the current version is already a pre-release.
// If it is, the bump is always BumpPreRelease (just increment the pre number).
// Otherwise the highest regular bump is promoted to its pre-release variant.
func PreReleaseBump(currentVersion string, highest changeset.BumpType) changeset.BumpType {
v, err := goSemver.NewVersion(currentVersion)
if err == nil && v.Prerelease() != "" {
return changeset.BumpPreRelease
}
switch highest {
case changeset.BumpMajor:
return changeset.BumpPreMajor
case changeset.BumpMinor:
return changeset.BumpPreMinor
default:
return changeset.BumpPrePatch
}
}
// CurrentVersion parses a version string and returns the semver object.
// It is exported so callers can inspect pre-release state without re-importing the semver library.
func CurrentVersion(version string) (*goSemver.Version, error) {