1 Commits
Author SHA1 Message Date
sneak ad6d5f24ac Report the Go build info version when linker flags set none (closes #422)
check / check (push) Successful in 12m14s
A `go install` of a tag sets no linker flags, so the binary reported
`dev`. Version, commit and commit date that the linker flags leave
unset now come from the build info Go records. Go records a
pseudo-version for an untagged commit and a `+dirty` suffix for a
modified checkout; `IsDevVersion` now counts both as development
builds, using `golang.org/x/mod`.

Model: opus-5-5
2026-11-11 01:27:53 +00:00
3 changed files with 27 additions and 16 deletions

No files matched your search

+18 -9
View File
@@ -1041,8 +1041,9 @@ is `git describe --tags --always --dirty`, which `script/version` runs for the
A `docker build .` of a clone, with no build arguments, runs the same
`git describe` (without `--dirty`) on the `.git` in its build context, so it
stamps the same value for a clean commit; the build fails if the context carries
`.git` and no version, commit or commit date comes out. `script/docker` and
`script/cibuild` stamp `unknown` when they run outside a git checkout.
`.git` and no version, commit or commit date comes out. `make` outside a git
checkout and `docker build .` without `.git` both stamp `dev`. `script/docker`
and `script/cibuild` stamp `unknown` when they run outside a git checkout.
A binary built by plain `go install` or `go build` carries no stamped version.
It reports the version Go recorded in it instead:
@@ -1056,13 +1057,21 @@ It reports the version Go recorded in it instead:
tag `v1.0.0` produces `vaultik 1.0.0`, matching the archive name
`vaultik_1.0.0_linux_amd64.tar.gz`. `goreleaser --snapshot` stamps
`dev-<12 chars of the commit sha>` rather than inventing the next patch number.
`vaultik version` calls a build a development build when its version is `dev`,
`unknown`, `dev-<sha>`, the short commit sha, `<tag>-<N>-g<short sha>` or a Go
pseudo-version, with or without `-dirty` or `+dirty`; only a plain tag, such as
`v1.0.0` or `1.0.0`, is a release. If `script/version` cannot be run at all,
`make` stops with an error instead of building an unversioned binary, and a
binary that somehow carries an empty version string still reports itself as a
development build.
`vaultik version` calls a build a development build when its version is one of
these:
- `dev` or `unknown`.
- `dev-<sha>`.
- the short commit sha.
- `<tag>-<N>-g<short sha>`.
- a Go pseudo-version.
- any version with a `-dirty` or `+dirty` suffix.
Only a plain tag, such as `v1.0.0` or `1.0.0`, is a release. If `script/version`
cannot be run at all, `make` stops with an error instead of building an
unversioned binary, and a binary that somehow carries an empty version string
still reports itself as a development build.
### cutting a release
+2 -2
View File
@@ -21,8 +21,8 @@ const shortCommitLen = 12
const exitCodeInterrupted = 130
// Entry is the main entry point for the CLI application.
// It first takes the version, commit and commit date the linker flags
// left unset from the Go build info (see globals.FromBuildInfo).
// It first calls globals.UseBuildInfo, which fills in the version,
// commit and commit date that the linker flags did not set.
// It prints the startup banner to stderr (unless a banner-suppressing
// flag is present in os.Args — see bannerSuppressedInArgs), executes the
// root cobra command, and routes any returned error through the
+7 -5
View File
@@ -53,11 +53,13 @@ func UseBuildInfo() {
info, Version, Commit, CommitDate)
}
// FromBuildInfo returns version, commit and commitDate, with each one
// the linker flags left unset taken from info. A `go install` of a tag
// sets no linker flags, but Go records the tag as the main module's
// version. Go records the commit and its time only when it builds from
// a git checkout. The time is cut to a date, as the Makefile stamps it.
// FromBuildInfo returns version, commit and commitDate. Each one that
// still holds its default ("dev" or empty for the version, "unknown"
// for the others) is replaced by the value Go recorded in info. A
// `go install` of a tag sets no linker flags, but Go records the tag
// as the main module's version. Go records the commit and its time
// only when it builds from a git checkout. The time is cut to a date,
// as the Makefile stamps it.
func FromBuildInfo(
info *debug.BuildInfo, version, commit, commitDate string,
) (string, string, string) {