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 .`
This commit is contained in:
parent
58d658be66
commit
712aced7da
2 changed files with 42 additions and 0 deletions
33
internal/metadata/version.go
Normal file
33
internal/metadata/version.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
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()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue