version

package
v0.16.2-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package version provides semantic versioning utilities for release management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCommand

func NewCommand() *cobra.Command

NewCommand creates the next-version command

Types

type BumpType

type BumpType int

BumpType represents the type of version bump

const (
	BumpNone BumpType = iota
	BumpPatch
	BumpMinor
	BumpMajor
)

func DetermineBumpType

func DetermineBumpType(commits []changelog.ConventionalCommit) BumpType

DetermineBumpType analyzes commits and returns the highest bump type needed

type Calculator

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

Calculator handles version calculation for the release workflow

func NewCalculator

func NewCalculator(prefix string) *Calculator

NewCalculator creates a new version calculator for the default grammar with a custom prefix. An empty prefix defaults to "v".

func NewCalculatorWithGrammar added in v0.10.0

func NewCalculatorWithGrammar(spec taggrammar.Spec) *Calculator

NewCalculatorWithGrammar creates a version calculator that emits tags in the shape described by spec, so a caller with a non-default token, separator, or prefix gets a matching next version.

func (*Calculator) CalculateNext

func (c *Calculator) CalculateNext(currentDevVersion, nextEnvVersion string, commits []changelog.ConventionalCommit) (*Version, error)

CalculateNext determines the next version for the lowest environment Parameters:

  • currentDevVersion: current version in dev (may be empty or same as nextEnvVersion after promotion)
  • nextEnvVersion: version in the next environment (e.g., test)
  • commits: conventional commits between nextEnv's SHA and HEAD

Returns the calculated version with appropriate RC suffix

type ComponentVersionInputs

type ComponentVersionInputs struct {
	// CurrentDevVersion is the component's latest tag (the RC-counter base).
	CurrentDevVersion string
	// NextEnvVersion is the component's latest published (non-prerelease)
	// release tag (the bump base).
	NextEnvVersion string
	// Commits are the conventional commits in the component's scoped range.
	Commits []changelog.ConventionalCommit
	// Paths is the commit scope: the component's path plus its effective extra
	// paths (its extra_paths unioned with top-level shared_paths).
	Paths []string
	// Calc calculates versions under the component's resolved tag grammar.
	Calc *Calculator
}

ComponentVersionInputs holds everything a component's next version is derived from: its current version and release base read from its own strict tag namespace, the conventional commits in its path-scoped range, the paths that scoped that range, and a calculator under the component's tag grammar.

func ResolveComponentVersionInputs

func ResolveComponentVersionInputs(cfg *config.TrunkConfig, component, baseDir, baseSHA, headSHA string) (*ComponentVersionInputs, error)

ResolveComponentVersionInputs derives the version inputs for a named component. It is the single source of the component version scope: both `cascade next-version --component` and orchestrate's component version calculation call it, so the CLI preview and the production pipeline cannot drift.

The component reads and emits under its own strict tag prefix only, so a sibling's tags are invisible to it. The commit range is scoped to the component's path plus its effective extra paths (its extra_paths unioned with top-level shared_paths), so a commit that touches only a shared dependency the component declares still registers a bump.

Failing lookups surface as errors rather than reading as "no tags" or "no commits": a component read as tagless restarts at its v0.1.0-rc.0, a regressive mint that can collide with published tags, and an empty commit range silently under-bumps the calculated version.

baseDir scopes the tag lookups (empty means the working directory). baseSHA, when non-empty, overrides the release-tag-derived base of the commit range; headSHA is the range head (callers pass "HEAD" for the current tip).

func ResolveComponentVersionInputsFor

func ResolveComponentVersionInputsFor(resolved *config.ResolvedComponent, baseDir, baseSHA, headSHA string) (*ComponentVersionInputs, error)

ResolveComponentVersionInputsFor is ResolveComponentVersionInputs for a component whose config the caller has ALREADY resolved. It is the entry point for a runtime that plans against the component's resolved config: such a config declares no nested components of its own, so the component can no longer be resolved out of it and the root-config entry point above cannot be used. Both entry points share this one derivation, so the CLI preview and the production pipeline cannot drift.

type Version

type Version struct {
	Major      int
	Minor      int
	Patch      int
	PreRelease int    // -1 means no pre-release suffix, >= 0 is the RC number
	Hotfix     int    // -1 means no hotfix segment, >= 0 is the hotfix number
	Prefix     string // e.g., "v" or custom prefix
	// contains filtered or unexported fields
}

Version represents a semantic version with optional pre-release suffix

func Parse

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

Parse parses a version string into a Version struct under the default grammar.

func ParseBaseWithGrammar added in v0.10.0

func ParseBaseWithGrammar(spec taggrammar.Spec, s string) (*Version, error)

ParseBaseWithGrammar parses the numeric core (prefix and major.minor.patch) of s under spec, tolerating and discarding any pre-release suffix such as an -rc.N, -dryrun.N, or other exercise tag that the strict Parse rejects. The returned Version always has no pre-release or hotfix segment. It errors only when the core itself is not a valid vX.Y.Z triple. Version calculations that derive their next version solely from a base can use this so a stray suffixed value recorded as the latest does not abort the whole calculation.

func ParseWithGrammar added in v0.10.0

func ParseWithGrammar(spec taggrammar.Spec, s string) (*Version, error)

ParseWithGrammar parses s into a Version under spec. The numeric fields come from the canonical grammar so the two never drift; the prefix is the literal run the tag leads with, which the grammar has already validated.

func (*Version) Base

func (v *Version) Base() string

Base returns the version without pre-release suffix

func (*Version) BaseVersion

func (v *Version) BaseVersion() *Version

BaseVersion returns a copy without pre-release suffix

func (*Version) Bump

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

Bump returns a new version with the specified bump applied

func (*Version) Compare added in v0.2.0

func (v *Version) Compare(other *Version) int

Compare returns -1, 0, or +1 reporting whether v sorts before, equal to, or after other under semver precedence. It compares major, minor, and patch numerically; then a version with a pre-release sorts before one without; then pre-release numbers compare numerically; then a version without a hotfix segment sorts before one with a hotfix; then hotfix numbers compare numerically.

func (*Version) Equal

func (v *Version) Equal(other *Version) bool

Equal returns true if two versions have the same major.minor.patch (ignoring RC)

func (*Version) NextHotfix added in v0.2.0

func (v *Version) NextHotfix() *Version

NextHotfix returns a copy of the version with its hotfix number incremented. If the version has no hotfix segment yet, the result is hotfix 1, so an rc.2 version becomes rc.2.hotfix.1.

func (*Version) String

func (v *Version) String() string

String returns the version as a string. The prefix and numeric core come from the version's own fields; the pre-release token and separator come from its grammar, so a custom grammar renders its own shape while the default renders the historical "-rc." form.

func (*Version) WithGrammar added in v0.10.0

func (v *Version) WithGrammar(spec taggrammar.Spec) *Version

WithGrammar returns a copy of v that renders under spec, so a version parsed with ParseWithGrammar carries its grammar through subsequent copy operations (WithHotfix, WithRC, Bump) and renders its configured pre-release shape. The zero/default grammar is preserved as-is, so a default version is unchanged.

func (*Version) WithHotfix added in v0.2.0

func (v *Version) WithHotfix(m int) *Version

WithHotfix returns a copy of the version with the given hotfix number, preserving the major, minor, patch, pre-release, and prefix.

func (*Version) WithRC

func (v *Version) WithRC(rc int) *Version

WithRC returns a copy with the specified RC number

Jump to

Keyboard shortcuts

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