-
Notifications
You must be signed in to change notification settings - Fork 1k
/
version.go
49 lines (44 loc) · 1.2 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Package version executes and returns the version string
// for the currently running process.
package version
import (
"fmt"
"log"
"os/exec"
"strconv"
"strings"
"time"
)
// The value of these vars are set through linker options.
var gitCommit = "Local build"
var buildDate = "Moments ago"
var buildDateUnix = "0"
var gitTag = "Unknown"
// Version returns the version string of this build.
func Version() string {
if buildDate == "{DATE}" {
now := time.Now().Format(time.RFC3339)
buildDate = now
}
if buildDateUnix == "{DATE_UNIX}" {
buildDateUnix = strconv.Itoa(int(time.Now().Unix()))
}
return fmt.Sprintf("%s. Built at: %s", BuildData(), buildDate)
}
// SemanticVersion returns the Major.Minor.Patch version of this build.
func SemanticVersion() string {
return gitTag
}
// BuildData returns the git tag and commit of the current build.
func BuildData() 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)
}