github.com/argoproj/argo-cd@v1.8.7/common/version.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "runtime" 6 ) 7 8 // Version information set by link flags during build. We fall back to these sane 9 // default values when we build outside the Makefile context (e.g. go run, go build, or go test). 10 var ( 11 version = "99.99.99" // value from VERSION file 12 buildDate = "1970-01-01T00:00:00Z" // output from `date -u +'%Y-%m-%dT%H:%M:%SZ'` 13 gitCommit = "" // output from `git rev-parse HEAD` 14 gitTag = "" // output from `git describe --exact-match --tags HEAD` (if clean tree state) 15 gitTreeState = "" // determined from `git status --porcelain`. either 'clean' or 'dirty' 16 ) 17 18 // Version contains Argo version information 19 type Version struct { 20 Version string 21 BuildDate string 22 GitCommit string 23 GitTag string 24 GitTreeState string 25 GoVersion string 26 Compiler string 27 Platform string 28 } 29 30 func (v Version) String() string { 31 return v.Version 32 } 33 34 // GetVersion returns the version information 35 func GetVersion() Version { 36 var versionStr string 37 38 if gitCommit != "" && gitTag != "" && gitTreeState == "clean" { 39 // if we have a clean tree state and the current commit is tagged, 40 // this is an official release. 41 versionStr = gitTag 42 } else { 43 // otherwise formulate a version string based on as much metadata 44 // information we have available. 45 versionStr = "v" + version 46 if len(gitCommit) >= 7 { 47 versionStr += "+" + gitCommit[0:7] 48 if gitTreeState != "clean" { 49 versionStr += ".dirty" 50 } 51 } else { 52 versionStr += "+unknown" 53 } 54 } 55 return Version{ 56 Version: versionStr, 57 BuildDate: buildDate, 58 GitCommit: gitCommit, 59 GitTag: gitTag, 60 GitTreeState: gitTreeState, 61 GoVersion: runtime.Version(), 62 Compiler: runtime.Compiler, 63 Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), 64 } 65 }