From 6bf3b3c4649b6e97269df596f200cce9a58d7cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sat, 16 Aug 2025 12:35:30 -0700 Subject: [PATCH] fix(version): allow build info to be set with LDFLAGS and fallback to VCS metadata when available --- internal/version/version.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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() + } +}