mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
feat(version): use Golang's builtin vcs feature to get commit and build date
This commit is contained in:
parent
88d9682f5f
commit
c1af510ead
2 changed files with 42 additions and 17 deletions
|
@ -3,9 +3,36 @@
|
|||
|
||||
package version // import "miniflux.app/v2/internal/version"
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Variables populated at build time.
|
||||
var (
|
||||
Version = "dev"
|
||||
Commit = "HEAD"
|
||||
BuildDate = "undefined"
|
||||
Version = "Development Version"
|
||||
Commit = getCommit()
|
||||
BuildDate = getBuildDate()
|
||||
)
|
||||
|
||||
func getCommit() string {
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
for _, setting := range info.Settings {
|
||||
if setting.Key == "vcs.revision" {
|
||||
return setting.Value[:8] // Short commit hash
|
||||
}
|
||||
}
|
||||
}
|
||||
return "HEAD"
|
||||
}
|
||||
|
||||
func getBuildDate() string {
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
for _, setting := range info.Settings {
|
||||
if setting.Key == "vcs.time" {
|
||||
return setting.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
return time.Now().Format(time.RFC3339)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue