calver

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BucketKey added in v0.59.0

func BucketKey(tokens []Token, requested []TokenKind, v Values) (string, error)

BucketKey returns a key that uniquely identifies which rotation bucket v belongs to, given the tokens a rotating changelog output/tag pattern groups by. requested must be a valid, non-empty prefix of tokens' own token order (see ValidateRotationTokens, which BucketKey calls internally). The key always renders in the format's own token order, regardless of the order requested was given in, so two callers who spell the same rotation differently still agree on the bucket.

func BucketPattern added in v0.59.0

func BucketPattern(tokens []Token, requested []TokenKind, v Values) (string, error)

BucketPattern returns a regular expression matching any bare version string in the same rotation bucket as v, given the tokens a rotating changelog output/tag pattern groups by. The pattern is anchored at the start (^) only — callers compose their own tag_prefix quoting and decide whether to anchor the end. requested must be a valid, non-empty prefix of tokens' own token order (see ValidateRotationTokens, which BucketPattern calls internally — this also guarantees the token immediately after the rotation boundary is a literal separator, so the match can never partial-match into the next token's digits).

func CompareVersions added in v0.77.0

func CompareVersions(a, b string) int

CompareVersions compares two dot-separated version strings component by component, reading each as an integer (zero padding is just a number; a missing or non-numeric component counts as 0). Returns -1 if a < b, 0 if a == b, 1 if a > b.

func RenderToken added in v0.59.0

func RenderToken(kind TokenKind, v Values) string

RenderToken formats the value v holds for a single non-literal token kind — the same per-token-kind formatting RenderVersion and the bucket helpers use internally, exported so a caller substituting individual {TOKEN} placeholders (rather than rendering a whole version string) doesn't need to duplicate the padding rules (e.g. "%04d" for YYYY).

func RenderVersion

func RenderVersion(tokens []Token, v Values) string

RenderVersion formats a version string from tokens and values.

func ValidateRotationTokens added in v0.59.0

func ValidateRotationTokens(tokens []Token, requested []TokenKind) error

ValidateRotationTokens checks that requested — the set of format tokens a rotating changelog output or tag-scope pattern groups by — forms a contiguous, non-empty prefix of tokens' own non-PATCH, non-literal token order, immediately followed by a literal separator in the format. A changelog can only rotate by dimensions the version format itself already tracks, in the order it tracks them, with an unambiguous boundary — so tag-scoping stays derivable from the version string alone, with no risk of a partial-digit false match (see docs/superpowers/specs/2026-08-28-changelog-rotation-design.md §1, §4).

Types

type Resolver

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

Resolver resolves the next CalVer version from the current date and git tags.

func New

func New(runner port.Runner, cfg *config.Config, now func() time.Time) *Resolver

New constructs a CalVer Resolver. now is injectable for deterministic tests.

func (*Resolver) BumpAuto

func (r *Resolver) BumpAuto(_ []string, _ []string) (string, error)

BumpAuto is not used by the CalVer calculator; it satisfies the VersionCalculator interface for internal/versioning/perenv.

func (*Resolver) BumpFromDate

func (r *Resolver) BumpFromDate(tags []string) (string, error)

BumpFromDate computes the next CalVer version from date only, without querying git. tags is a caller-provided slice of bare version strings (no prefix), newest first. Implements the VersionCalculator interface consumed by internal/versioning/perenv.

func (*Resolver) Resolve

func (r *Resolver) Resolve() (versioning.Result, error)

Resolve returns the next CalVer version result.

type Token

type Token struct {
	Kind    TokenKind
	Literal string // non-empty only when Kind == KindLiteral
}

Token is one component of a parsed CalVer format string.

func ParseFormat

func ParseFormat(format string) ([]Token, error)

ParseFormat parses a CalVer format string (e.g. "YYYY.MM.PATCH") into tokens. Returns an error if PATCH is absent or not the last non-literal token.

type TokenKind

type TokenKind int

TokenKind identifies a CalVer format token.

const (
	KindLiteral TokenKind = iota
	KindYYYY
	KindMM
	KindDD
	KindWW
	KindQQ
	KindSS
	KindSPRINT
	KindPATCH
)

func TokenKindFromName added in v0.59.0

func TokenKindFromName(name string) (TokenKind, bool)

TokenKindFromName returns the TokenKind for a format-token spelling (e.g. "YYYY"), or false if name isn't a recognized token — the inverse of TokenKind.String(). Used by callers (e.g. internal/app's changelog-rotation decorator) that parse {TOKEN} placeholders out of a user-authored string and need the typed value BucketKey/BucketPattern/ValidateRotationTokens expect.

func (TokenKind) String added in v0.59.0

func (k TokenKind) String() string

String returns the format-token spelling for k (e.g. "YYYY"), for use in error messages.

type Values

type Values struct {
	Year, Month, Day, Week, Quarter, Semester, Sprint, Patch int
}

Values holds the numeric components extracted from a CalVer version string.

func ParseVersion

func ParseVersion(tokens []Token, version string) (Values, error)

ParseVersion extracts values from a version string using the given token sequence.

Jump to

Keyboard shortcuts

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