Skip to content

Commit ee68f17

Browse files
dhaiducekopenshift-merge-robot
authored andcommitted
Fetch build version if version wasn't set at build time
ref: https://issues.redhat.com/browse/ACM-5803 Signed-off-by: Dale Haiducek <[email protected]>
1 parent 680d005 commit ee68f17

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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
5354
GIT_VERSION := $(shell git describe --dirty 2>/dev/null)
5455
ifndef GIT_VERSION

cmd/PolicyGenerator/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
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))

0 commit comments

Comments
 (0)