ChronoTomato/internal/metadata/version.go
Sebastian Mark 09dbf35a6a feat!: introduce ChronoTomatoVersion
- 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 .`
2024-11-10 09:35:02 +01:00

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()
}
}
}