File tree Expand file tree Collapse file tree 1 file changed +31
-4
lines changed
Expand file tree Collapse file tree 1 file changed +31
-4
lines changed Original file line number Diff line number Diff line change 66 "context"
77 "fmt"
88 "regexp"
9+ "runtime/debug"
910 "strconv"
1011
1112 "github.com/obolnetwork/charon/app/errors"
@@ -22,9 +23,9 @@ var version = "v1.6-rc"
2223var Version , _ = Parse (version ) // Error is caught in tests.
2324
2425var (
25- // These variables are populated with build information via -ldflags.
26- vcsRevision = "unknown "
27- vcsTime = "unknown "
26+ // These variables are populated with build information via -ldflags when binaries are built, but not in Dockerfile .
27+ vcsRevision = ""
28+ vcsTime = ""
2829)
2930
3031// Supported returns the supported minor versions in order of precedence.
@@ -42,7 +43,33 @@ func Supported() []SemVer {
4243
4344// GitCommit returns the git commit hash and timestamp from build info.
4445func GitCommit () (hash string , timestamp string ) {
45- return vcsRevision , vcsTime
46+ if vcsRevision != "" {
47+ return vcsRevision , vcsTime
48+ }
49+
50+ hash , timestamp = "unknown" , "unknown"
51+ hashLen := 7
52+
53+ info , ok := debug .ReadBuildInfo ()
54+ if ! ok {
55+ return hash , timestamp
56+ }
57+
58+ for _ , s := range info .Settings {
59+ switch s .Key {
60+ case "vcs.revision" :
61+ if len (s .Value ) < hashLen {
62+ hashLen = len (s .Value )
63+ }
64+
65+ hash = s .Value [:hashLen ]
66+ case "vcs.time" :
67+ timestamp = s .Value
68+ default :
69+ }
70+ }
71+
72+ return hash , timestamp
4673}
4774
4875// LogInfo logs charon version information along-with the provided message.
You can’t perform that action at this time.
0 commit comments