version

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package version messages - error and log message constants Exported so tests can compare against them

Index

Constants

View Source
const (
	ErrCannotDecrementMajor = "cannot decrement major version below 0"
	ErrCannotDecrementMinor = "cannot decrement minor version below 0"
	ErrCannotDecrementPatch = "cannot decrement patch version below 0"
	ErrInvalidVersionLevel  = "invalid version level"
	ErrCustomKeyNotFound    = "custom key not found"
)

Error messages

View Source
const (
	LogVersionLoaded      = "version_loaded"
	LogVersionSaved       = "version_saved"
	LogVersionIncremented = "version_incremented"
	LogVersionDecremented = "version_decremented"
	LogVersionMigrated    = "version_migrated"
	LogVersionParsed      = "version_parsed"
	LogVersionParseError  = "version_parse_error"
	LogVersionCreated     = "version_created"
	LogCustomVarSet       = "custom_var_set"
	LogCustomVarDeleted   = "custom_var_deleted"
	LogVersionSet         = "version_set"
	LogPrefixSet          = "prefix_set"
	LogFileReadError      = "file_read_error"
	LogFileWriteError     = "file_write_error"
)

Log messages for structured logging

View Source
const (
	// FilePermission is the default permission for created files (owner rw, group/other r)
	FilePermission os.FileMode = 0644
)

File permission constants

Variables

This section is empty.

Functions

func Decrement

func Decrement(level VersionLevel) error

Decrement decrements the specified version level

func EscapedBranchName

func EscapedBranchName(branchName string) string

EscapedBranchName takes a branch name and escapes slashes to dashes

func GetCurrentVersion

func GetCurrentVersion() (string, error)

GetCurrentVersion reads the current version from VERSION file

func GetPrefix

func GetPrefix() (string, error)

GetPrefix returns the current version prefix

func Increment

func Increment(level VersionLevel) error

Increment increments the specified version level

func Save

func Save(v *Version) error

Save writes the version to the VERSION file. Validates the version by round-tripping through the parser before writing.

func SetMetadata

func SetMetadata(metadata string) error

SetMetadata sets the build metadata

func SetPreRelease

func SetPreRelease(preRelease string) error

SetPreRelease sets the pre-release tag

func SetPrefix

func SetPrefix(prefix string) error

SetPrefix sets the version prefix in the VERSION file The VERSION file is the source of truth - config.Prefix is only used as default for new projects

func SetVersion added in v0.1.0

func SetVersion(versionString string) error

SetVersion sets the VERSION file to the given version string. Validates the input through the parser grammar before writing.

func StripPrefix

func StripPrefix(version string) string

StripPrefix removes the 'v' or 'V' prefix from a version string if present

Types

type Version

type Version struct {
	Prefix        string // Optional prefix ("v" or "V" only, per SemVer convention)
	Major         int    // Major version
	Minor         int    // Minor version
	Patch         int    // Patch version
	Revision      *int   // Optional 4th component (nil = 3-component, non-nil = 4-component assembly/MS-style)
	PreRelease    string // Pre-release identifier (e.g., "alpha.1")
	BuildMetadata string // Build metadata (e.g., "build.123")
	Raw           string // Original parsed string
}

Version represents a semantic version with all components This is the unified struct replacing both SemVer and VersionData

func Load

func Load() (*Version, error)

Load reads the VERSION file and returns the parsed Version If VERSION doesn't exist, creates a default 0.0.1 (using config prefix if set) VERSION file content is the source of truth - it takes priority over config

func Parse

func Parse(version string) Version

Parse parses a version string into a Version struct using the grammar-based parser. Returns a Version with zero values for unparseable input (lenient parsing). For strict parsing with error reporting, use ParseStrict.

func ParseStrict added in v0.1.0

func ParseStrict(version string) (*Version, error)

ParseStrict parses a version string with full validation. Returns an error if the version string is invalid according to the grammar.

func (*Version) AssemblyVersion

func (v *Version) AssemblyVersion() string

AssemblyVersion returns an assembly-compatible version (Major.Minor.Patch.Revision) Uses actual Revision if set, otherwise defaults to 0

func (*Version) BuildMetadataWithPlus

func (v *Version) BuildMetadataWithPlus() string

BuildMetadataWithPlus returns the build metadata with a leading plus, or empty if none

func (*Version) CoreVersion

func (v *Version) CoreVersion() string

CoreVersion returns just Major.Minor.Patch[.Revision]

func (*Version) DecrementMajor

func (v *Version) DecrementMajor() error

DecrementMajor decrements the major version, returns error if already 0

func (*Version) DecrementMinor

func (v *Version) DecrementMinor() error

DecrementMinor decrements the minor version, returns error if already 0

func (*Version) DecrementPatch

func (v *Version) DecrementPatch() error

DecrementPatch decrements the patch version, returns error if already 0

func (*Version) FullSemVer

func (v *Version) FullSemVer() string

FullSemVer returns Major.Minor.Patch[-PreRelease][+BuildMetadata]

func (*Version) FullString

func (v *Version) FullString() string

FullString returns the full version string with prefix Format: [Prefix]Major.Minor.Patch[-PreRelease][+BuildMetadata]

func (*Version) HasBuildMetadata

func (v *Version) HasBuildMetadata() bool

HasBuildMetadata returns true if this version has build metadata

func (*Version) HasPrefix

func (v *Version) HasPrefix() bool

HasPrefix returns true if the version has a prefix

func (*Version) HasRevision added in v0.1.0

func (v *Version) HasRevision() bool

HasRevision returns true if this is a 4-component version

func (*Version) IncrementMajor

func (v *Version) IncrementMajor()

IncrementMajor increments the major version, resets minor, patch, and revision

func (*Version) IncrementMinor

func (v *Version) IncrementMinor()

IncrementMinor increments the minor version, resets patch and revision

func (*Version) IncrementPatch

func (v *Version) IncrementPatch()

IncrementPatch increments the patch version, resets revision

func (*Version) IsPreRelease

func (v *Version) IsPreRelease() bool

IsPreRelease returns true if this version has a pre-release tag

func (*Version) MajorMinor

func (v *Version) MajorMinor() string

MajorMinor returns the Major.Minor string

func (*Version) MajorString

func (v *Version) MajorString() string

MajorString returns the major version as a string

func (*Version) MinorString

func (v *Version) MinorString() string

MinorString returns the minor version as a string

func (*Version) OriginalFullSemVer

func (v *Version) OriginalFullSemVer() string

OriginalFullSemVer returns the full semver string preserving the original prefix style

func (*Version) OriginalSemVerString

func (v *Version) OriginalSemVerString() string

OriginalSemVerString returns the semver string preserving the original prefix style

func (*Version) OriginalString

func (v *Version) OriginalString() string

OriginalString returns the version in the same format as the input

func (*Version) PatchString

func (v *Version) PatchString() string

PatchString returns the patch version as a string

func (*Version) PreReleaseLabel

func (v *Version) PreReleaseLabel() string

PreReleaseLabel returns just the label portion of the pre-release (e.g., "alpha" from "alpha.5")

func (*Version) PreReleaseLabelWithDash

func (v *Version) PreReleaseLabelWithDash() string

PreReleaseLabelWithDash returns the pre-release label with a leading dash, or empty if none

func (*Version) PreReleaseNumber

func (v *Version) PreReleaseNumber() int

PreReleaseNumber returns the numeric portion of the pre-release (e.g., 5 from "alpha.5") Returns -1 if no numeric portion exists

func (*Version) PreReleaseWithDash

func (v *Version) PreReleaseWithDash() string

PreReleaseWithDash returns the pre-release with a leading dash, or empty if none

func (*Version) PrefixedFullSemVer

func (v *Version) PrefixedFullSemVer() string

PrefixedFullSemVer returns Major.Minor.Patch[-PreRelease][+BuildMetadata] with the original prefix

func (*Version) PrefixedSemVerString

func (v *Version) PrefixedSemVerString() string

PrefixedSemVerString returns Major.Minor.Patch[-PreRelease] format with the original prefix

func (*Version) PrefixedString

func (v *Version) PrefixedString() string

PrefixedString returns the version with prefix (Major.Minor.Patch)

func (*Version) RevisionString added in v0.1.0

func (v *Version) RevisionString() string

RevisionString returns the revision as a string (0 if not set)

func (*Version) RevisionValue added in v0.1.0

func (v *Version) RevisionValue() int

RevisionValue returns the revision number (0 if not set)

func (*Version) SemVer

func (v *Version) SemVer() string

SemVer returns Major.Minor.Patch[-PreRelease] (no metadata)

func (*Version) SemVerString

func (v *Version) SemVerString() string

SemVerString returns Major.Minor.Patch[-PreRelease] format without prefix

func (*Version) String

func (v *Version) String() string

String returns the SemVer 2.0.0 compliant string (no prefix) Format: Major.Minor.Patch[-PreRelease][+BuildMetadata]

func (*Version) Validate

func (v *Version) Validate() error

Validate checks if the version is valid according to SemVer 2.0.0. Uses the grammar-based parser for validation via round-trip.

type VersionLevel

type VersionLevel int

VersionLevel represents the semantic version component to modify

const (
	MajorLevel VersionLevel = iota
	MinorLevel
	PatchLevel
)

Jump to

Keyboard shortcuts

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