Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ clean:
# build section
############################################################
# Parse the version using git, with fallbacks as follows:
# - git describe (i.e. vX.Y.Z-<sha>)
# - git describe (i.e. vX.Y.Z-<extra_commits>-<sha>)
# - <branch>-<sha>
# - <sha>-dev
# - Go BuildInfo version
# - Unversioned binary
GIT_VERSION := $(shell git describe --dirty 2>/dev/null)
ifndef GIT_VERSION
Expand Down
10 changes: 9 additions & 1 deletion cmd/PolicyGenerator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"os"
runtimeDebug "runtime/debug"
"strings"

"github.com/spf13/pflag"
Expand All @@ -22,7 +23,14 @@ func main() {

if *versionFlag {
if Version == "" {
Version = "Unversioned binary"
// Gather the version from the build info
if info, ok := runtimeDebug.ReadBuildInfo(); ok {
Version = info.Main.Version
}

if Version == "" {
Version = "Unversioned binary"
}
}
//nolint:forbidigo
fmt.Println(strings.TrimSpace(Version))
Expand Down