Files
sow-tools/internal/buildinfo/buildinfo.go

34 lines
897 B
Go

// Package buildinfo reports the Crucible build version.
//
// Version is empty in plain `go build`; the build scripts and Dockerfile inject
// the short git sha via -ldflags. As a fallback we read the VCS revision that
// the Go toolchain stamps into the binary, so a binary built without -ldflags
// still self-identifies.
package buildinfo
import "runtime/debug"
// Version is overridable at link time:
//
// -ldflags "-X git.westgate.pw/ShadowsOverWestgate/sow-tools/internal/buildinfo.Version=<sha>"
var Version = ""
// String returns a human-readable version line, e.g. "crucible 8f31c2a".
func String() string {
return "crucible " + revision()
}
func revision() string {
if Version != "" {
return Version
}
if bi, ok := debug.ReadBuildInfo(); ok {
for _, s := range bi.Settings {
if s.Key == "vcs.revision" && s.Value != "" {
return s.Value
}
}
}
return "devel"
}