mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
7f3dc5a2dd
* Add the latest git tag as part of the version string. Example: version=Prysm/v1.0.0-alpha.10/28e61fa40c7d16774b3b1c18d8382c64537bfa84. Built at: 2020-06-11 04:29:18+00:00 * add user agent Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
40 lines
993 B
Go
40 lines
993 B
Go
// Package version executes and returns the version string
|
|
// for the currently running process.
|
|
package version
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os/exec"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// The value of these vars are set through linker options.
|
|
var gitCommit = "Local build"
|
|
var buildDate = "Moments ago"
|
|
var gitTag = "Unknown"
|
|
|
|
// GetVersion returns the version string of this build.
|
|
func GetVersion() string {
|
|
if buildDate == "{DATE}" {
|
|
now := time.Now().Format(time.RFC3339)
|
|
buildDate = now
|
|
}
|
|
return fmt.Sprintf("%s. Built at: %s", GetBuildData(), buildDate)
|
|
}
|
|
|
|
// GetBuildData returns the git tag and commit of the current build.
|
|
func GetBuildData() 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.Println(err)
|
|
} else {
|
|
gitCommit = strings.TrimRight(string(commit), "\r\n")
|
|
}
|
|
}
|
|
return fmt.Sprintf("Prysm/%s/%s", gitTag, gitCommit)
|
|
}
|