version

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 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 (
	ErrMajorVersionNegative  = "major version cannot be negative"
	ErrMinorVersionNegative  = "minor version cannot be negative"
	ErrPatchVersionNegative  = "patch version cannot be negative"
	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"
	ErrInvalidPreRelease     = "invalid pre-release identifier"
	ErrInvalidMetadata       = "invalid build metadata"
	ErrEmptyIdentifierPart   = "identifier part cannot be empty"
	ErrInvalidIdentifierChar = "invalid character in identifier"
	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"
	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

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 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 (e.g., "v", "release-")
	Major         int    // Major version
	Minor         int    // Minor version
	Patch         int    // Patch version
	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.0 (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 Extracts prefix as all characters (letters, dashes) before the first digit Returns a Version with zero values for unparseable input

func (*Version) AssemblyVersion

func (v *Version) AssemblyVersion() string

AssemblyVersion returns an assembly-compatible version (Major.Minor.Patch.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

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

func (v *Version) IncrementMajor()

IncrementMajor increments the major version, resets minor and patch

func (*Version) IncrementMinor

func (v *Version) IncrementMinor()

IncrementMinor increments the minor version, resets patch

func (*Version) IncrementPatch

func (v *Version) IncrementPatch()

IncrementPatch increments the patch version

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

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