version

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatCalVer

func FormatCalVer(t time.Time, format string) string

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 StripPrefix

func StripPrefix(tag, prefix string) string

StripPrefix removes a prefix (e.g., "v") from a version string.

func WithPrefix

func WithPrefix(version, prefix string) string

WithPrefix adds a prefix (e.g., "v") to a version string.

Types

type BumpType

type BumpType string

BumpType indicates which part of a semver to increment.

const (
	BumpMajor BumpType = "major"
	BumpMinor BumpType = "minor"
	BumpPatch BumpType = "patch"
)

type Scheme

type Scheme string

Scheme represents the versioning scheme (semver or calver).

const (
	SchemeSemVer Scheme = "semver"
	SchemeCalVer Scheme = "calver"
)

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

func NextCalVer(current *Version, format string, now time.Time) *Version

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

func ParseCalVer(s string) (*Version, error)

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 ParseSemVer

func ParseSemVer(s string) (*Version, error)

ParseSemVer parses a semantic version string (without prefix). Format: MAJOR.MINOR.PATCH[-PRERELEASE][+METADATA]

func (*Version) BumpSemVer

func (v *Version) BumpSemVer(bump BumpType) *Version

BumpSemVer increments the version according to the bump type.

func (*Version) String

func (v *Version) String() string

String returns the string representation of the version (without prefix).

func (*Version) WithMetadata

func (v *Version) WithMetadata(meta string) *Version

WithMetadata returns a new version with the build metadata set.

func (*Version) WithPrerelease

func (v *Version) WithPrerelease(pre string) *Version

WithPrerelease returns a new version with the prerelease identifier set.

Jump to

Keyboard shortcuts

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