prysm-pulse/shared/version/version.go
mkinney da6c270d46 report git commit and date on local build (#3904)
* report git commit and date on local build

* switch to using time package
2019-11-01 13:47:30 +08:00

31 lines
711 B
Go

package version
import (
"fmt"
"log"
"strings"
"os/exec"
"time"
)
// 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 {
// 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 {
log.Fatal(err)
}
gitCommit = strings.TrimRight(string(commit), "\r\n")
}
if buildDate == "{DATE}" {
now := time.Now().Format(time.RFC3339)
buildDate = now
}
return fmt.Sprintf("Git commit: %s. Built at: %s", gitCommit, buildDate)
}