Documentation
¶
Overview ¶
Package version messages - error and log message constants Exported so tests can compare against them
Index ¶
- Constants
- func Decrement(level VersionLevel) error
- func EscapedBranchName(branchName string) string
- func GetCurrentVersion() (string, error)
- func GetPrefix() (string, error)
- func Increment(level VersionLevel) error
- func ModuleName() (string, error)
- func ModulePath() (string, error)
- func Save(v *Version) error
- func SetChangeCheck(check ChangeCheck)
- func SetMetadata(metadata string) error
- func SetPreRelease(preRelease string) error
- func SetPrefix(prefix string) error
- func SetVersion(versionString string) error
- func StripPrefix(version string) string
- type ChangeCheck
- type Version
- func (v *Version) AssemblyVersion() string
- func (v *Version) BuildMetadataWithPlus() string
- func (v *Version) CoreVersion() string
- func (v *Version) DecrementMajor() error
- func (v *Version) DecrementMinor() error
- func (v *Version) DecrementPatch() error
- func (v *Version) FullSemVer() string
- func (v *Version) FullString() string
- func (v *Version) HasBuildMetadata() bool
- func (v *Version) HasPrefix() bool
- func (v *Version) HasRevision() bool
- func (v *Version) IncrementMajor()
- func (v *Version) IncrementMinor()
- func (v *Version) IncrementPatch()
- func (v *Version) IsPreRelease() bool
- func (v *Version) MajorMinor() string
- func (v *Version) MajorString() string
- func (v *Version) MinorString() string
- func (v *Version) OriginalFullSemVer() string
- func (v *Version) OriginalSemVerString() string
- func (v *Version) OriginalString() string
- func (v *Version) PatchString() string
- func (v *Version) PreReleaseLabel() string
- func (v *Version) PreReleaseLabelWithDash() string
- func (v *Version) PreReleaseNumber() int
- func (v *Version) PreReleaseWithDash() string
- func (v *Version) PrefixedFullSemVer() string
- func (v *Version) PrefixedSemVerString() string
- func (v *Version) PrefixedString() string
- func (v *Version) RevisionString() string
- func (v *Version) RevisionValue() int
- func (v *Version) SemVer() string
- func (v *Version) SemVerString() string
- func (v *Version) String() string
- func (v *Version) Validate() error
- type VersionLevel
Constants ¶
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
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
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 ¶
EscapedBranchName takes a branch name and escapes slashes to dashes
func GetCurrentVersion ¶
GetCurrentVersion reads the current version from VERSION file
func Increment ¶
func Increment(level VersionLevel) error
Increment increments the specified version level
func ModuleName ¶ added in v0.3.0
ModuleName returns the bare name of the directory holding the active VERSION file ("tools" for internal/tools), empty at the repository root. It suits component-style tag conventions outside the Go ecosystem, such as "tools-v1.2.3", where the separator is a matter of convention rather than a requirement of the module system.
func ModulePath ¶ added in v0.3.0
ModulePath returns the directory holding the active VERSION file, relative to the repository root, slash-separated and terminated with a slash. It is empty when the VERSION file sits at the repository root, when no VCS is active, or when the repository root cannot be determined.
The trailing slash is deliberate. Go requires a submodule's tag to be the module's directory path followed by the version ("internal/tools/v1.2.3"), so a single template — "{{ModulePath}}{{Prefix}}{{MajorMinorPatch}}" — renders correctly both inside a module subdirectory and at the repository root, where ModulePath contributes nothing.
func Save ¶
Save writes the version to the VERSION file. Validates the version by round-tripping through the parser, then runs the change check (SetChangeCheck), before writing.
func SetChangeCheck ¶ added in v0.3.0
func SetChangeCheck(check ChangeCheck)
SetChangeCheck sets the check every version change runs before VERSION is written (nil for none). The command line sets it to check the configured file updates, so a refused update refuses the version change too.
func SetPreRelease ¶
SetPreRelease sets the pre-release tag
func SetPrefix ¶
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
SetVersion sets the VERSION file to the given version string. Validates the input through the parser grammar before writing.
func StripPrefix ¶
StripPrefix removes the 'v' or 'V' prefix from a version string if present
Types ¶
type ChangeCheck ¶ added in v0.3.0
ChangeCheck judges the version a command is about to write. A non-nil error refuses the change, and the VERSION file is left as it was.
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 ¶
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 ¶
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
ParseStrict parses a version string with full validation. Returns an error if the version string is invalid according to the grammar.
func (*Version) AssemblyVersion ¶
AssemblyVersion returns an assembly-compatible version (Major.Minor.Patch.Revision) Uses actual Revision if set, otherwise defaults to 0
func (*Version) BuildMetadataWithPlus ¶
BuildMetadataWithPlus returns the build metadata with a leading plus, or empty if none
func (*Version) CoreVersion ¶
CoreVersion returns just Major.Minor.Patch[.Revision]
func (*Version) DecrementMajor ¶
DecrementMajor decrements the major version, returns error if already 0
func (*Version) DecrementMinor ¶
DecrementMinor decrements the minor version, returns error if already 0
func (*Version) DecrementPatch ¶
DecrementPatch decrements the patch version, returns error if already 0
func (*Version) FullSemVer ¶
FullSemVer returns Major.Minor.Patch[-PreRelease][+BuildMetadata]
func (*Version) FullString ¶
FullString returns the full version string with prefix Format: [Prefix]Major.Minor.Patch[-PreRelease][+BuildMetadata]
func (*Version) HasBuildMetadata ¶
HasBuildMetadata returns true if this version has build metadata
func (*Version) HasRevision ¶ added in v0.1.0
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 ¶
IsPreRelease returns true if this version has a pre-release tag
func (*Version) MajorMinor ¶
MajorMinor returns the Major.Minor string
func (*Version) MajorString ¶
MajorString returns the major version as a string
func (*Version) MinorString ¶
MinorString returns the minor version as a string
func (*Version) OriginalFullSemVer ¶
OriginalFullSemVer returns the full semver string preserving the original prefix style
func (*Version) OriginalSemVerString ¶
OriginalSemVerString returns the semver string preserving the original prefix style
func (*Version) OriginalString ¶
OriginalString returns the version in the same format as the input
func (*Version) PatchString ¶
PatchString returns the patch version as a string
func (*Version) PreReleaseLabel ¶
PreReleaseLabel returns just the label portion of the pre-release (e.g., "alpha" from "alpha.5")
func (*Version) PreReleaseLabelWithDash ¶
PreReleaseLabelWithDash returns the pre-release label with a leading dash, or empty if none
func (*Version) PreReleaseNumber ¶
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 ¶
PreReleaseWithDash returns the pre-release with a leading dash, or empty if none
func (*Version) PrefixedFullSemVer ¶
PrefixedFullSemVer returns Major.Minor.Patch[-PreRelease][+BuildMetadata] with the original prefix
func (*Version) PrefixedSemVerString ¶
PrefixedSemVerString returns Major.Minor.Patch[-PreRelease] format with the original prefix
func (*Version) PrefixedString ¶
PrefixedString returns the version with prefix (Major.Minor.Patch)
func (*Version) RevisionString ¶ added in v0.1.0
RevisionString returns the revision as a string (0 if not set)
func (*Version) RevisionValue ¶ added in v0.1.0
RevisionValue returns the revision number (0 if not set)
func (*Version) SemVerString ¶
SemVerString returns Major.Minor.Patch[-PreRelease] format without prefix
type VersionLevel ¶
type VersionLevel int
VersionLevel represents the semantic version component to modify
const ( MajorLevel VersionLevel = iota MinorLevel PatchLevel )