2019-01-10 04:19:33 +00:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-11-01 05:47:30 +00:00
|
|
|
"log"
|
|
|
|
"os/exec"
|
2019-11-01 14:48:24 +00:00
|
|
|
"strings"
|
2019-11-01 05:47:30 +00:00
|
|
|
"time"
|
2019-01-10 04:19:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// The value of these vars are set through linker options.
|
|
|
|
var gitCommit = "Local build"
|
|
|
|
var buildDate = "Moments ago"
|
|
|
|
|
|
|
|
// GetVersion returns the version string of this build.
|
|
|
|
func GetVersion() string {
|
2019-11-01 05:47:30 +00:00
|
|
|
// if doing a local build, these values are not interpolated
|
|
|
|
if gitCommit == "{STABLE_GIT_COMMIT}" {
|
|
|
|
commit, err := exec.Command("git", "rev-parse", "HEAD").Output()
|
|
|
|
if err != nil {
|
2019-11-06 18:41:06 +00:00
|
|
|
log.Println(err)
|
|
|
|
} else {
|
|
|
|
gitCommit = strings.TrimRight(string(commit), "\r\n")
|
2019-11-01 05:47:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if buildDate == "{DATE}" {
|
|
|
|
now := time.Now().Format(time.RFC3339)
|
|
|
|
buildDate = now
|
|
|
|
}
|
2019-12-13 18:52:28 +00:00
|
|
|
return fmt.Sprintf("Prysm/Git commit: %s. Built at: %s", gitCommit, buildDate)
|
2019-01-10 04:19:33 +00:00
|
|
|
}
|