diff --git a/internal/version/version.go b/internal/version/version.go index 9bd8f3c8..4af4eea5 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -7,11 +7,11 @@ import ( "runtime/debug" ) -// Variables populated at build time. +// Variables populated at build time when using LD_FLAGS. var ( - Version = "Development Version" - Commit = getCommit() - BuildDate = getBuildDate() + Version = "" + Commit = "" + BuildDate = "" ) func getCommit() string { @@ -38,3 +38,17 @@ func getBuildDate() string { } return "Unknown (built outside VCS)" } + +// Populate build information from VCS metadata if LDFLAGS are not set. +// Falls back to values from the Go module's build info when available. +func init() { + if Version == "" { + Version = "Development Version" + } + if Commit == "" { + Commit = getCommit() + } + if BuildDate == "" { + BuildDate = getBuildDate() + } +}