version

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 4 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

Overview

Package version defines how Angelia parses, orders and classifies upstream versions. Each scheme lives in its own subpackage (semver, pep440, calver, lexical); package schemes picks one per source kind and adds the lexical fallback.

Every function here is pure: no I/O, no shared state, safe for concurrent use.

Index

Constants

This section is empty.

Variables

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

ErrInvalid is wrapped by every parse error.

Functions

func CompareDigits

func CompareDigits(a, b string) int

CompareDigits compares two non-empty strings of ASCII digits by numeric value, without overflow: "007" == "7" < "10".

func IsDigits

func IsDigits(s string) bool

IsDigits reports whether s is a non-empty string of ASCII digits.

func Natural

func Natural(a, b string) int

Natural compares two strings in natural order: runs of ASCII digits compare by numeric value ("1.10" > "1.9"), other runs compare bytewise, and a string that is a prefix of the other sorts first. Strings that are equal under these rules (e.g. "1.01" and "1.1") are ordered bytewise, so Natural returns 0 only for identical strings.

func TrimZeros

func TrimZeros(digits string) string

TrimZeros strips leading zeros from a string of ASCII digits, keeping "0".

func Truncate

func Truncate(s string, n int) string

Truncate shortens s to at most n bytes, cut at a UTF-8 rune boundary, and appends "..." when it cut anything. Use it before logging or quoting untrusted upstream strings.

Types

type Bump

type Bump string

Bump is the kind of change between two versions, as used by the policy `bump: [major, minor]` filter and the event's bump field.

const (
	BumpMajor      Bump = "major"
	BumpMinor      Bump = "minor"
	BumpPatch      Bump = "patch"
	BumpPrerelease Bump = "prerelease"
	BumpOther      Bump = "other"
)

Bump values.

type ParseError

type ParseError struct {
	Scheme string
	Raw    string
	Reason string
}

ParseError describes why a raw string is not a valid version of a scheme.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

Unwrap makes errors.Is(err, ErrInvalid) true.

type Scheme

type Scheme interface {
	// Name is the scheme's identifier as used in configuration, e.g. "pep440".
	Name() string
	// Parse parses raw. Errors wrap ErrInvalid.
	Parse(raw string) (Version, error)
	// Compare returns -1 if a < b, 0 if a and b have the same precedence, +1 if a > b.
	Compare(a, b Version) int
	// IsPrerelease reports whether v is a pre-release (alpha, beta, rc, dev, ...).
	IsPrerelease(v Version) bool
	// Bump classifies the change from prev to next. It returns BumpOther
	// unless next is strictly greater than prev and both belong to the scheme.
	//
	// prev must be the greatest known version below next, not the latest
	// known version: when 2.0.0 is known and the backport 1.9.4 appears, pass
	// prev = 1.9.3 to get BumpPatch (with prev = 2.0.0 the result is BumpOther).
	Bump(prev, next Version) Bump
}

Scheme parses, orders and classifies the versions of one versioning scheme.

Compare, IsPrerelease and Bump accept any Version, never panic, and keep a total order when a set mixes schemes (which happens when unparseable versions fall back to lexical): versions of the scheme itself rank above versions of any other scheme, and foreign versions are ordered among themselves with Natural on their String form.

type Version

type Version interface {
	// String returns the normalized form, e.g. "1.0rc1" for the PEP 440 input "1.0-RC1".
	String() string
	// Scheme returns the name of the scheme that parsed the version.
	Scheme() string
}

Version is a parsed version. Each scheme has its own concrete type.

Never compare two Versions with == or use them as map keys: concrete types hold slices, and equal precedence is not identity. Use Scheme.Compare to order them and String to display them. Compare returning 0 does not mean the same version ("1.0" and "1.0.0" in PEP 440, "1.0.0+a" and "1.0.0+b" in SemVer), so key known-version sets by the raw upstream string.

Directories

Path Synopsis
Package calver implements calendar versioning for tags such as "2026.10.1", "2026.10.15", "2026.3", "24.04" and "24.04.1-rc1".
Package calver implements calendar versioning for tags such as "2026.10.1", "2026.10.15", "2026.3", "24.04" and "24.04.1-rc1".
Package lexical is the fallback version scheme: any non-blank string is a version, ordered by natural string order (version.Natural), so "1.10" sorts after "1.9".
Package lexical is the fallback version scheme: any non-blank string is a version, ordered by natural string order (version.Natural), so "1.10" sorts after "1.9".
Package pep440 implements Python version identifiers as specified by PEP 440 / the PyPA "Version specifiers" specification, including epochs, pre-, post- and dev-releases, local versions and the normalization rules (case, separators, spelling variants such as "alpha", "c", "rev", implicit numbers and implicit post-releases "1.0-1").
Package pep440 implements Python version identifiers as specified by PEP 440 / the PyPA "Version specifiers" specification, including epochs, pre-, post- and dev-releases, local versions and the normalization rules (case, separators, spelling variants such as "alpha", "c", "rev", implicit numbers and implicit post-releases "1.0-1").
Package schemes chooses the version scheme of a watch (by source kind, overridable per watch) and wraps it so that unparseable versions fall back to the lexical scheme instead of failing.
Package schemes chooses the version scheme of a watch (by source kind, overridable per watch) and wraps it so that unparseable versions fall back to the lexical scheme instead of failing.
Package semver implements Semantic Versioning 2.0.0 (https://semver.org) with the npm-style loose prefix: surrounding white space, a leading "=" and a leading "v" or "V" are accepted and dropped ("v1.2.3" == "1.2.3").
Package semver implements Semantic Versioning 2.0.0 (https://semver.org) with the npm-style loose prefix: surrounding white space, a leading "=" and a leading "v" or "V" are accepted and dropped ("v1.2.3" == "1.2.3").

Jump to

Keyboard shortcuts

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