Sebastian Mark
09dbf35a6a
- set version from `runtime/debug.Main.Version` - use latest git tag as fallback - allow version to be overwritten via ldflags - this will break `go build .` and `go install .`
29 lines
620 B
Go
29 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()
|
|
}
|
|
}
|
|
}
|