1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-26 18:21:01 +00:00

fix(version): allow build info to be set with LDFLAGS and fallback to VCS metadata when available

This commit is contained in:
Frédéric Guillot 2025-08-16 12:35:30 -07:00
parent a010544200
commit 6bf3b3c464

View file

@ -7,11 +7,11 @@ import (
"runtime/debug" "runtime/debug"
) )
// Variables populated at build time. // Variables populated at build time when using LD_FLAGS.
var ( var (
Version = "Development Version" Version = ""
Commit = getCommit() Commit = ""
BuildDate = getBuildDate() BuildDate = ""
) )
func getCommit() string { func getCommit() string {
@ -38,3 +38,17 @@ func getBuildDate() string {
} }
return "Unknown (built outside VCS)" 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()
}
}