buildinfo

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package buildinfo carries the version metadata that the linker stamps into the binary with -ldflags -X. A plain `go build` stamps nothing, so it reports "devel" and empty values.

Role

platform layer: build metadata that no module owns. It imports no package, so the version command and the composition root read it without depending on any module.

Inputs

  • make build: LDFLAGS in the Makefile stamps the version (git describe), the commit (git rev-parse HEAD) and the build time in UTC.
  • The image build: the Dockerfile stamps the version and the commit from its VERSION and COMMIT build arguments, which make docker sets. It stamps no build date. The tag of its golang build stage names the Go release the image's binary is built with.
  • The release build: .goreleaser.yaml stamps the version of the tag, the full commit and, as the build date, the commit date rather than the time of the build, so that the build is reproducible.

Outputs

  • Version: the stamped version, or "devel".
  • Commit and BuildDate: the stamped commit and date, or empty.
  • The version command (cmd/artifactweave) prints them. The composition root logs the version at startup and serves it as the revision of /artifactory/api/system/version.

Invariants

  • The import path and the names version, commit and buildDate are part of the build contract. The linker ignores -X for a symbol that does not exist, so renaming a variable, or moving the package without its flags, ships "devel" with no build error; TestUnitLdflagsStampThisPackage fails first.
  • Each variable stays uninitialized or initialized to a constant string. -X does not work on a variable whose initializer calls a function or refers to another variable, and nothing reports that either.
  • "devel" is also the version the Makefile and the Dockerfile fall back to when they have none; TestUnitDefaults pins it.
  • The Dockerfile's build stage names a full Go release, pinned by the digest of its multi-arch index, no older than the Go the unit tests run on: in CI, the release setup-go resolves from go.mod. The image's binary carries the standard library of the Go that builds it, so an image left behind ships without fixes that CI's tests and govulncheck already have, and nothing else reports it; TestUnitDockerfileGoNotBehindToolchain fails first. Dependabot moves the stage (.github/dependabot.yml, the docker entry for /).

References

Status

Implemented P0, from the repository template: make build stamps the package, and the version command and the revision of the system version read it. The image build has stamped it since #73, and the release build since #507, which brought the release binaries of P18 forward. Moved here in P9d. Its tests hold the image build's Go release to the toolchain's (#1208).

Testing

  • TestUnitDefaults: an unstamped build reports "devel" and empty values.
  • TestUnitLdflagsStampThisPackage: every -X flag in the Makefile, .goreleaser.yaml and the Dockerfile names this package's import path; the Makefile and .goreleaser.yaml stamp all three variables and the Dockerfile the version and the commit. The test takes the address of each variable, so renaming one fails to compile.
  • TestUnitDockerfileGoNotBehindToolchain: every golang stage of the Dockerfile names a full Go release pinned by digest, no older than the toolchain running the test. It skips on a prerelease or a development build, since the Dockerfile takes only released Go.
  • TestUnitDockerfileGoRuleDetectsViolations and TestUnitGoReleaseNamesOnlyReleases: each way the rule fails, and the runtime.Version forms it reads.

No test runs the linker, so the stamped values themselves show only when a built binary runs version: one from make build, make docker or a snapshot of the release config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDate

func BuildDate() string

BuildDate returns the RFC 3339 date stamped at link time, or empty: the build time for make build, the commit date for a release build, and nothing for the image build.

func Commit

func Commit() string

Commit returns the source commit, if known.

func Version

func Version() string

Version returns the release version or "devel".

Types

This section is empty.

Jump to

Keyboard shortcuts

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