34 lines
775 B
Go
34 lines
775 B
Go
|
package metadata
|
||
|
|
||
|
import (
|
||
|
"os/exec"
|
||
|
"runtime/debug"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
var ChronoTomatoVersion = "" // The GoTomato version
|
||
|
|
||
|
func stripVersionPrefix(version string) string {
|
||
|
return strings.TrimLeft(version, "v")
|
||
|
}
|
||
|
|
||
|
func getLatestTag() string {
|
||
|
bytes, _ := exec.Command("git", "describe", "--tags").Output()
|
||
|
output := strings.TrimSpace(string(bytes))
|
||
|
return stripVersionPrefix(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 = stripVersionPrefix(info.Main.Version)
|
||
|
} else {
|
||
|
ChronoTomatoVersion = getLatestTag()
|
||
|
}
|
||
|
}
|
||
|
}
|