semverutil

package
v0.64.5 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(v1, v2 string) int

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

func EnsureVPrefix(v string) string

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

func IsActionVersionTag(s string) bool

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

func IsCompatible(pinVersion, requestedVersion string) bool

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 IsValid

func IsValid(ref string) bool

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).

Types

type SemanticVersion

type SemanticVersion struct {
	Major int
	Minor int
	Patch int
	Pre   string
	Raw   string
}

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 v is strictly newer than other. Uses golang.org/x/mod/semver.Compare for proper semantic version comparison.

func (*SemanticVersion) IsPrecise

func (v *SemanticVersion) IsPrecise() bool

IsPrecise returns true if the version has explicit minor and patch components. For example, "v6.0.0" is precise, but "v6" is not.

Jump to

Keyboard shortcuts

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