semver

package
v0.14.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package semver provides semantic versioning operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatTag

func FormatTag(v Version) string

FormatTag formats a version as a git tag (e.g., "v1.2.3").

func FormatTagWithPrefix

func FormatTagWithPrefix(v Version, prefix string) string

FormatTagWithPrefix formats a version as a git tag with the given prefix. prefix="v" → "v1.2.3"; prefix="" → "1.2.3"; prefix="release-" → "release-1.2.3". Use this instead of Version.Tag() when tag-prefix is configurable.

func FormatVersion

func FormatVersion(v Version) string

FormatVersion formats a version for output (e.g., "1.2.3").

Types

type BumpType

type BumpType int

BumpType indicates what type of version bump is needed.

const (
	BumpNone BumpType = iota
	BumpPatch
	BumpMinor
	BumpMajor
)

func DetectBumpType

func DetectBumpType(commitTypes []string, rules ...map[string]string) BumpType

DetectBumpType analyzes commit types and returns the appropriate bump type. An optional rules map (map[string]string) overrides the built-in mapping. Built-in: "breaking-change"→BumpMajor, "feat"→BumpMinor, "fix"→BumpPatch.

IMPORTANT: "BREAKING CHANGE" (with space) is NOT a trigger in the built-in switch. Callers must inject "breaking-change" (hyphenated) into commitTypes for commits with a "!" suffix or "BREAKING CHANGE:" footer.

The variadic parameter accepts map[string]string (compatible with conventional.BumpRules = map[string]BumpLevel = map[string]string).

func (BumpType) String

func (b BumpType) String() string

String returns a human-readable name for the bump type.

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

Version represents a semantic version.

func BootstrapVersion

func BootstrapVersion(commitTypes []string) Version

BootstrapVersion returns the initial version when no tags exist. First "feat" commit → v0.1.0 First "fix" commit → v0.0.1 "breaking-change" → v1.0.0 No commits or unrecognized types → v0.0.0

func NextVersion

func NextVersion(current Version, bump BumpType) Version

NextVersion calculates the next version based on bump type. If bump is BumpNone, returns current version unchanged.

func ParseVersion

func ParseVersion(s string) (Version, error)

ParseVersion parses a version string (e.g., "1.2.3" or "v1.2.3"). Returns Version and error if parsing fails.

func ParseVersionFromTag

func ParseVersionFromTag(tagName, prefix string) (Version, error)

ParseVersionFromTag strips the given prefix from tagName, then calls ParseVersion. Returns an error if tagName does not start with prefix. Example: ParseVersionFromTag("v1.2.3", "v") → Version{1,2,3}

ParseVersionFromTag("release-2.0.0", "release-") → Version{2,0,0}
ParseVersionFromTag("1.2.3", "") → Version{1,2,3}

func (Version) String

func (v Version) String() string

String returns the version as "X.Y.Z".

func (Version) Tag deprecated

func (v Version) Tag() string

Tag returns the version as a git tag "vX.Y.Z".

Deprecated: use FormatTagWithPrefix(v, "v") for configurable prefix support. This method hardcodes the "v" prefix and cannot reflect a custom tag-prefix.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL