Documentation
¶
Overview ¶
Package semverutil provides shared semantic versioning primitives used across the pkg/workflow and pkg/cli packages. Centralizing these helpers ensures that semver parsing, comparison, and compatibility logic is fixed in one place.
Both workflow and cli packages previously duplicated the "ensure v-prefix" pattern and independently called golang.org/x/mod/semver. This package provides the canonical implementations so both packages can delegate here.
Index ¶
- func Compare(v1, v2 string) int
- func EnsureVPrefix(v string) string
- func IsActionVersionTag(s string) bool
- func IsCompatible(pinVersion, requestedVersion string) bool
- func IsMorePreciseVersion(v1, v2 string) bool
- func IsValid(ref string) bool
- func NormalizeGitDescribeSemver(v string) string
- type SemanticVersion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare compares two semantic versions and returns 1 if v1 > v2, -1 if v1 < v2, or 0 if they are equal. A bare version without a leading "v" is accepted.
func EnsureVPrefix ¶
EnsureVPrefix returns v with a leading "v" added if it is not already present. The golang.org/x/mod/semver package requires the "v" prefix; callers that may receive bare version strings (e.g. "1.2.3") should normalise via this helper.
func IsActionVersionTag ¶
IsActionVersionTag reports whether s is a valid GitHub Actions version tag. Accepted formats are vmajor, vmajor.minor, and vmajor.minor.patch; prerelease and build-metadata suffixes are not accepted.
func IsCompatible ¶
IsCompatible reports whether pinVersion is semver-compatible with requestedVersion. Semver compatibility is defined as both versions sharing the same major version.
Examples:
- IsCompatible("v5.0.0", "v5") → true
- IsCompatible("v5.1.0", "v5.0.0") → true
- IsCompatible("v6.0.0", "v5") → false
func IsMorePreciseVersion ¶ added in v0.82.0
IsMorePreciseVersion reports whether v1 should sort ahead of v2 in the action-version specificity ordering. Versions with more dot-separated components sort first (for example "v4.3.0" ahead of "v4"), and ties use lexicographic ordering. This is an ordering predicate, not a strict "more-precise-only" check. No validation is performed; callers should ensure both inputs are well-formed version tags.
func IsValid ¶
IsValid reports whether ref is a valid semantic version string. It uses golang.org/x/mod/semver and accepts any valid semver, including prerelease and build-metadata suffixes. A bare version without a leading "v" is also accepted (the prefix is added internally).
func NormalizeGitDescribeSemver ¶ added in v0.82.11
NormalizeGitDescribeSemver collapses local git-describe compiler versions to their base release tag for compatibility checks.
Examples:
- v1.2.3-27-gabc1234 -> v1.2.3
- v1.2.3-27-gabc1234-dirty -> v1.2.3
- v1.2.3-dirty -> v1.2.3
- v1.2.3-beta.1 -> v1.2.3-beta.1
Types ¶
type SemanticVersion ¶
SemanticVersion represents a parsed semantic version.
func ParseVersion ¶
func ParseVersion(v string) *SemanticVersion
ParseVersion parses v into a SemanticVersion. It returns nil if v is not a valid semantic version string.
func (*SemanticVersion) IsNewer ¶
func (v *SemanticVersion) IsNewer(other *SemanticVersion) bool
IsNewer returns true if this version is newer than other. Uses Compare for proper semantic version comparison.
func (*SemanticVersion) IsPreciseVersion ¶ added in v0.65.1
func (v *SemanticVersion) IsPreciseVersion() bool
IsPreciseVersion returns true if the version has explicit minor and patch components (i.e., at least two dots in the version string, e.g. "v6.0.0" is precise, "v6" is not).