2024-11-06 17:36:49 +00:00
|
|
|
package version
|
2017-03-16 07:39:28 +00:00
|
|
|
|
2024-11-03 00:47:15 +00:00
|
|
|
import (
|
|
|
|
_ "embed"
|
|
|
|
"strings"
|
|
|
|
)
|
2018-11-20 10:13:42 +00:00
|
|
|
|
2024-11-03 00:47:15 +00:00
|
|
|
// Use go:generate script to get the version and git commit.
|
|
|
|
// VERSION and GIT_COMMIT files are used in further `go:embed` commands to load values to the variables.
|
|
|
|
// Suppress errors, assuming files have already been properly generated. Required for Docker builds.
|
2024-11-06 17:36:49 +00:00
|
|
|
//go:generate sh -c "../../_assets/scripts/version.sh > VERSION || true"
|
2024-11-03 00:47:15 +00:00
|
|
|
//go:generate sh -c "git rev-parse --short HEAD > GIT_COMMIT || true"
|
|
|
|
|
|
|
|
var (
|
|
|
|
// version is defined in git tags.
|
|
|
|
// We set it from the Makefile.
|
|
|
|
//go:embed VERSION
|
|
|
|
version string
|
|
|
|
|
|
|
|
// gitCommit is a commit hash.
|
|
|
|
//go:embed GIT_COMMIT
|
|
|
|
gitCommit string
|
|
|
|
)
|
2022-08-11 14:27:25 +00:00
|
|
|
|
2024-11-03 00:47:15 +00:00
|
|
|
func init() {
|
|
|
|
version = strings.TrimSpace(version)
|
|
|
|
gitCommit = strings.TrimSpace(gitCommit)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Version() string {
|
|
|
|
return version
|
|
|
|
}
|
|
|
|
|
|
|
|
func GitCommit() string {
|
|
|
|
return gitCommit
|
|
|
|
}
|