version

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package version provides versioning strategies for calculating release versions.

Index

Constants

View Source
const DefaultCalVerFormat = "YYYY.0M.MICRO"

Variables

View Source
var ErrInvalidVersion = errors.New("invalid version")

Functions

func ValidateCalVerFormat added in v0.6.1

func ValidateCalVerFormat(format string) error

Types

type CalVer

type CalVer struct {
	Format string
	Prefix string
	Now    func() time.Time
}

CalVer implements calendar versioning. Supported formats use CalVer date tokens and a MICRO incrementing counter.

func (*CalVer) Current

func (c *CalVer) Current(tag string) (string, error)

func (*CalVer) InitialVersion

func (c *CalVer) InitialVersion() string

InitialVersion returns an empty string since calver starts from the current date.

func (*CalVer) Less added in v0.6.1

func (c *CalVer) Less(leftVersion, rightVersion, leftRef, rightRef string) bool

func (*CalVer) Next

func (c *CalVer) Next(current string, bump commit.BumpType) (string, error)

Next increments the micro counter if the current calendar period matches. Otherwise, it resets the micro counter to 1.

func (*CalVer) Tag

func (c *CalVer) Tag(version string) string

type CalVerScheme added in v0.8.0

type CalVerScheme struct {
	// contains filtered or unexported fields
}

CalVerScheme is a compiled CalVer format ready to extract per-token values from a version string. Construct via NewCalVerScheme; treat as opaque.

func NewCalVerScheme added in v0.8.0

func NewCalVerScheme(format string) (*CalVerScheme, error)

NewCalVerScheme compiles the format once and returns a reusable scheme. The empty string compiles to DefaultCalVerFormat.

func (*CalVerScheme) Format added in v0.8.0

func (s *CalVerScheme) Format() string

Format returns the raw format string the scheme was compiled from.

func (*CalVerScheme) HasDay added in v0.8.0

func (s *CalVerScheme) HasDay() bool

HasDay reports whether the format addresses a day component.

func (*CalVerScheme) HasMonth added in v0.8.0

func (s *CalVerScheme) HasMonth() bool

HasMonth reports whether the format addresses a month component.

func (*CalVerScheme) HasWeek added in v0.8.0

func (s *CalVerScheme) HasWeek() bool

HasWeek reports whether the format addresses a week component.

func (*CalVerScheme) MarkerValues added in v0.8.0

func (s *CalVerScheme) MarkerValues(version string) (map[MarkerToken]string, error)

MarkerValues parses a CalVer-shaped version string and returns rendered strings for each addressable token, keyed by canonical token name. Widths match the format's tokens (e.g. 0M zero-pads to 2). Tokens not present in the format are absent from the map.

type MarkerToken added in v0.8.0

type MarkerToken string

MarkerToken names the addressable components of a parsed version string. Marker-based version-file updaters use these to look up the rendered value for a given file marker (e.g. x-yeet-month).

const (
	MarkerTokenYear  MarkerToken = "year"
	MarkerTokenMonth MarkerToken = "month"
	MarkerTokenWeek  MarkerToken = "week"
	MarkerTokenDay   MarkerToken = "day"
	MarkerTokenMicro MarkerToken = "micro"
)

type SemVer

type SemVer struct {
	Prefix                     string
	PreMajorBreakingBumpsMinor bool
	PreMajorFeaturesBumpPatch  bool
}

func (*SemVer) Current

func (s *SemVer) Current(tag string) (string, error)

func (*SemVer) InitialVersion

func (s *SemVer) InitialVersion() string

func (*SemVer) Next

func (s *SemVer) Next(current string, bump commit.BumpType) (string, error)

func (*SemVer) Tag

func (s *SemVer) Tag(version string) string

type Strategy

type Strategy interface {
	// Current parses a version tag string into a normalized version.
	Current(tag string) (string, error)
	// Next calculates the next version based on the current version and bump type.
	Next(current string, bump commit.BumpType) (string, error)
}

Jump to

Keyboard shortcuts

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