github.com/prysmaticlabs/prysm@v1.4.4/shared/version/version.go (about) 1 // Package version executes and returns the version string 2 // for the currently running process. 3 package version 4 5 import ( 6 "fmt" 7 "log" 8 "os/exec" 9 "strconv" 10 "strings" 11 "time" 12 ) 13 14 // The value of these vars are set through linker options. 15 var gitCommit = "Local build" 16 var buildDate = "Moments ago" 17 var buildDateUnix = "0" 18 var gitTag = "Unknown" 19 20 // Version returns the version string of this build. 21 func Version() string { 22 if buildDate == "{DATE}" { 23 now := time.Now().Format(time.RFC3339) 24 buildDate = now 25 } 26 if buildDateUnix == "{DATE_UNIX}" { 27 buildDateUnix = strconv.Itoa(int(time.Now().Unix())) 28 } 29 return fmt.Sprintf("%s. Built at: %s", BuildData(), buildDate) 30 } 31 32 // SemanticVersion returns the Major.Minor.Patch version of this build. 33 func SemanticVersion() string { 34 return gitTag 35 } 36 37 // BuildData returns the git tag and commit of the current build. 38 func BuildData() string { 39 // if doing a local build, these values are not interpolated 40 if gitCommit == "{STABLE_GIT_COMMIT}" { 41 commit, err := exec.Command("git", "rev-parse", "HEAD").Output() 42 if err != nil { 43 log.Println(err) 44 } else { 45 gitCommit = strings.TrimRight(string(commit), "\r\n") 46 } 47 } 48 return fmt.Sprintf("Prysm/%s/%s", gitTag, gitCommit) 49 }