2023-06-19 14:42:47 -07:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-11-19 21:10:04 -08:00
|
|
|
|
2023-08-10 19:46:45 -07:00
|
|
|
package version // import "miniflux.app/v2/internal/version"
|
2017-11-19 21:10:04 -08:00
|
|
|
|
2025-08-16 11:54:15 -07:00
|
|
|
import (
|
|
|
|
"runtime/debug"
|
|
|
|
)
|
|
|
|
|
2025-08-16 12:35:30 -07:00
|
|
|
// Variables populated at build time when using LD_FLAGS.
|
2020-10-18 15:00:10 -07:00
|
|
|
var (
|
2025-08-16 12:35:30 -07:00
|
|
|
Version = ""
|
|
|
|
Commit = ""
|
|
|
|
BuildDate = ""
|
2020-10-18 15:00:10 -07:00
|
|
|
)
|
2025-08-16 11:54:15 -07:00
|
|
|
|
|
|
|
func getCommit() string {
|
|
|
|
if info, ok := debug.ReadBuildInfo(); ok {
|
|
|
|
for _, setting := range info.Settings {
|
|
|
|
if setting.Key == "vcs.revision" {
|
2025-08-16 12:13:30 -07:00
|
|
|
if len(setting.Value) >= 8 {
|
|
|
|
return setting.Value[:8]
|
|
|
|
}
|
|
|
|
return setting.Value
|
2025-08-16 11:54:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-08-16 12:13:30 -07:00
|
|
|
return "Unknown (built outside VCS)"
|
2025-08-16 11:54:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func getBuildDate() string {
|
|
|
|
if info, ok := debug.ReadBuildInfo(); ok {
|
|
|
|
for _, setting := range info.Settings {
|
|
|
|
if setting.Key == "vcs.time" {
|
|
|
|
return setting.Value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-08-16 12:13:30 -07:00
|
|
|
return "Unknown (built outside VCS)"
|
2025-08-16 11:54:15 -07:00
|
|
|
}
|
2025-08-16 12:35:30 -07:00
|
|
|
|
|
|
|
// 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()
|
|
|
|
}
|
|
|
|
}
|