File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -46,9 +46,10 @@ clean:
4646# build section
4747# ###########################################################
4848# Parse the version using git, with fallbacks as follows:
49- # - git describe (i.e. vX.Y.Z-<sha>)
49+ # - git describe (i.e. vX.Y.Z-<extra_commits>-< sha>)
5050# - <branch>-<sha>
5151# - <sha>-dev
52+ # - Go BuildInfo version
5253# - Unversioned binary
5354GIT_VERSION := $(shell git describe --dirty 2>/dev/null)
5455ifndef GIT_VERSION
Original file line number Diff line number Diff line change 44 "bytes"
55 "fmt"
66 "os"
7+ runtimeDebug "runtime/debug"
78 "strings"
89
910 "github.com/spf13/pflag"
@@ -22,7 +23,14 @@ func main() {
2223
2324 if * versionFlag {
2425 if Version == "" {
25- Version = "Unversioned binary"
26+ // Gather the version from the build info
27+ if info , ok := runtimeDebug .ReadBuildInfo (); ok {
28+ Version = info .Main .Version
29+ }
30+
31+ if Version == "" {
32+ Version = "Unversioned binary"
33+ }
2634 }
2735 //nolint:forbidigo
2836 fmt .Println (strings .TrimSpace (Version ))
You can’t perform that action at this time.
0 commit comments