Documentation
¶
Overview ¶
Package versioning implements immutable application versions and build metadata.
Application versions have the form MAJOR.MINOR.PATCH+YYYYMMDD.PR. Source snapshots insert -snapshot before the plus sign. These application identities are distinct from the ordinary SemVer tags used to release this Go module. Next selects the calendar date of the final commit in America/Sao_Paulo.
Applications can inject Info fields through their own linker variables and pass them to Current. Runtime discovery reads only the main executable's Go build information; it never inspects a working directory or a dependency's repository. Repository inspection and tag allocation belong to gitversion.
Index ¶
Constants ¶
const UnknownVersion = "0.0.0+unknown"
UnknownVersion identifies a build with no known application version.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bump ¶
type Bump string
Bump selects the numeric component to advance before allocating a version.
const ( // BumpInherit keeps the previous core. The empty Bump has the same meaning. BumpInherit Bump = "inherit" // BumpMajor increments Major and resets Minor and Patch. BumpMajor Bump = "major" // BumpMinor increments Minor and resets Patch. BumpMinor Bump = "minor" // BumpPatch increments Patch. BumpPatch Bump = "patch" )
type Core ¶
Core is the numeric SemVer core shared by successive application builds.
func ParseCore ¶
ParseCore parses three unsigned decimal components without leading zeroes. Components larger than uint64 are rejected.
type Info ¶
type Info struct {
Version string `json:"version"`
Commit string `json:"commit"`
BuildTime string `json:"build_time"`
}
Info describes an application build. Empty Commit and BuildTime mean unknown; Commit, when present, is a full 40- or 64-digit hexadecimal identity, and BuildTime, when present, is RFC3339. Version uses UnknownVersion when unknown.
func Current ¶
Current resolves injection against the main executable's build information. Complete valid injection bypasses runtime build-information discovery.
func ReadBuildInfo ¶
func ReadBuildInfo() Info
ReadBuildInfo reads metadata from the main executable's embedded Go build information. It never uses dependency module versions or probes a repository. Ordinary module versions and unavailable application versions become unknown. The VCS revision and time, when present, are returned for Resolve to validate.
func Resolve ¶
Resolve validates and combines injected and embedded application metadata. Complete injection wins without inspecting embedded fields. Partial injection takes precedence field by field, but conflicting full commit identities are rejected. Ordinary embedded Go module versions are treated as absent. An explicit injected UnknownVersion is preserved rather than filled in.
type Version ¶
Version identifies one application build. Date is a calendar date, PR is a positive pull request number, and Snapshot distinguishes untagged source builds. Values returned by Parse and Next satisfy these constraints.
func Next ¶
Next allocates a release identity using commitTime's calendar date in America/Sao_Paulo. The time must be present, PR positive, and bump valid. This pure calculation does not inspect Git or create a tag.
func Parse ¶
Parse parses an application release or snapshot version without a Git tag prefix. It rejects unknown versions, invalid calendar dates, and overflow.
func ParseTag ¶
ParseTag parses a canonical v-prefixed application release tag or a legacy build/ tag. The bool reports a legacy tag, including when its suffix is invalid. Snapshot tags and ordinary module release tags are rejected.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
go-versioning
command
|
|
|
examples
|
|
|
app
command
The app example reads metadata from its own binary without running Git.
|
The app example reads metadata from its own binary without running Git. |
|
Package gitversion inspects explicit Git repositories and allocates immutable application tags.
|
Package gitversion inspects explicit Git repositories and allocates immutable application tags. |