30 lines
620 B
Go
30 lines
620 B
Go
|
package metadata
|
||
|
|
||
|
import (
|
||
|
"os/exec"
|
||
|
"runtime/debug"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
var ChronoTomatoVersion = ""
|
||
|
|
||
|
func getLatestTag() string {
|
||
|
bytes, _ := exec.Command("git", "describe", "--tags").Output()
|
||
|
output := strings.TrimSpace(string(bytes))
|
||
|
return output
|
||
|
}
|
||
|
|
||
|
// set GoTomatoVersion from runtime/debug.Main.Version
|
||
|
// use latest git tag as fallback
|
||
|
// can be overwritten via ldflags (e,g. by goreleaser)
|
||
|
func init() {
|
||
|
if ChronoTomatoVersion == "" {
|
||
|
info, _ := debug.ReadBuildInfo()
|
||
|
if info.Main.Version != "(devel)" {
|
||
|
ChronoTomatoVersion = info.Main.Version
|
||
|
} else {
|
||
|
ChronoTomatoVersion = getLatestTag()
|
||
|
}
|
||
|
}
|
||
|
}
|