Documentation
¶
Index ¶
- func Compare(a, b *Version) int
- func FormatCalVer(t time.Time, format string) string
- func IncrementHotfixSequence(tag string) (string, error)
- func IsHotfixVersion(tag string) bool
- func StripPrefix(tag, prefix string) string
- func ValidateMetadataIdentifiers(meta string) error
- func ValidatePrereleaseIdentifiers(pre string) error
- func ValidateSingleIdentifier(id string) error
- func WithPrefix(version, prefix string) string
- type BumpType
- type Scheme
- type Version
- func (v *Version) BumpPreRelease(channel string) (*Version, error)
- func (v *Version) BumpSemVer(bump BumpType) *Version
- func (v *Version) Graduate() *Version
- func (v *Version) IsPrerelease() bool
- func (v *Version) IsStable() bool
- func (v *Version) String() string
- func (v *Version) WithMetadata(meta string) *Version
- func (v *Version) WithPrerelease(pre string) *Version
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶ added in v1.3.0
Compare compares two SemVer versions according to spec §11. Returns -1 if a < b, 0 if a == b, 1 if a > b. Build metadata (§10) is ignored for precedence.
func FormatCalVer ¶
FormatCalVer formats a time using the given format string, with support for ISO week numbers. Supports special format codes: - "YYYY" or "2006" for 4-digit year - "WW" for ISO week number (01-53) All other format codes are passed to time.Format(). Examples: - "2006.01.02" -> "2025.10.03" (year.month.day) - "2006.WW" -> "2025.40" (year.week)
func IncrementHotfixSequence ¶ added in v1.3.0
IncrementHotfixSequence bumps the hotfix sequence number. "v1.0.0-hotfix.2" → "v1.0.0-hotfix.3"
func IsHotfixVersion ¶ added in v1.3.0
IsHotfixVersion checks if version string has hotfix suffix. Examples: "v1.0.0-hotfix.1", "2025.11.09-hotfix.2", "api/v1.0.0-patch.1"
func StripPrefix ¶
StripPrefix removes a prefix (e.g., "v") from a version string.
func ValidateMetadataIdentifiers ¶ added in v1.3.0
ValidateMetadataIdentifiers validates a build metadata string against spec §10. Identifiers are dot-separated; each must match [0-9A-Za-z-]+.
func ValidatePrereleaseIdentifiers ¶ added in v1.3.0
ValidatePrereleaseIdentifiers validates a prerelease string against spec §9. Identifiers are dot-separated; each must match [0-9A-Za-z-]+. Numeric-only identifiers must not have leading zeros.
func ValidateSingleIdentifier ¶ added in v1.3.0
ValidateSingleIdentifier validates a single (no-dot) identifier for use as a prerelease channel.
func WithPrefix ¶
WithPrefix adds a prefix (e.g., "v") to a version string.
Types ¶
type Version ¶
type Version struct {
Scheme Scheme
Raw string
// SemVer fields
Major int
Minor int
Patch int
Pre string
Meta string
// CalVer fields
CalVerDate string // e.g., "2025.10.02"
CalVerSequence int // optional sequence number for same-day releases
}
Version represents a parsed version tag.
func NextCalVer ¶
NextCalVer generates the next calendar version using the given format and current time. If the current version is for the same period (e.g., same day/week), it increments the sequence number. Supports special format codes via FormatCalVer (e.g., "WW" for ISO week number).
For week-based formats (containing "WW"), build numbers start at 1 for clarity. For date-based formats, build numbers start at 0 (omitted) for the first release.
func ParseCalVer ¶
ParseCalVer parses a calendar version string (without prefix). Format: YYYY.MM.DD[.SEQUENCE][-PRERELEASE][+METADATA]
or: YYYY.WW[.SEQUENCE][-PRERELEASE][+METADATA]
Supports both date-based (3 parts: year.month.day) and week-based (2 parts: year.week) formats.
func ParseHotfixVersion ¶ added in v1.3.0
ParseHotfixVersion parses versions like "v1.0.0-hotfix.3". Returns base version, suffix, and sequence number.
func ParseSemVer ¶
ParseSemVer parses a semantic version string (without prefix). Format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]
func (*Version) BumpPreRelease ¶ added in v1.3.0
BumpPreRelease returns a new version with an updated prerelease identifier. The base (major.minor.patch) is preserved.
Rules:
- Same channel → increment counter: "rc.1" → "rc.2"
- Different channel or no prior counter → reset to 1: "alpha.2" + channel "rc" → "rc.1"
- channel must be a single valid spec §9 identifier (no dots allowed)
func (*Version) BumpSemVer ¶
BumpSemVer increments the version according to the bump type.
func (*Version) Graduate ¶ added in v1.3.0
Graduate returns a new version with prerelease and metadata cleared, preserving major.minor.patch. Use this to promote a prerelease to a stable release.
func (*Version) IsPrerelease ¶ added in v1.3.0
IsPrerelease reports whether the version has a prerelease identifier (spec §9).
func (*Version) IsStable ¶ added in v1.3.0
IsStable reports whether the version is a stable release (no prerelease identifier).
func (*Version) WithMetadata ¶
WithMetadata returns a new version with the build metadata set.
func (*Version) WithPrerelease ¶
WithPrerelease returns a new version with the prerelease identifier set.