Skip to content

Commit fb6694f

Browse files
authored
Fix --version flag (#3428)
Our build scripts had regression: we were not passing version information to `go build` correctly. As a result running the binary with `--version` was not printing version and commit sha: ``` OLM version: git commit: ``` Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 5a01f50 commit fb6694f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Diff for: Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@ export CGO_ENABLED ?= 0
7171
export GO111MODULE ?= on
7272
export GIT_REPO := $(shell go list -m)
7373
export GIT_COMMIT := $(shell git rev-parse HEAD)
74-
export VERSION := $(shell cat OLM_VERSION)
7574
export VERSION_PATH := ${GIT_REPO}/pkg/version
7675

76+
ifeq ($(origin VERSION), undefined)
77+
VERSION := $(shell git describe --tags --always --dirty)
78+
endif
79+
export VERSION
80+
7781
# GO_BUILD flags are set with = to allow for re-evaluation of the variables
7882
export GO_BUILD_ASMFLAGS = all=-trimpath=$(PWD)
7983
export GO_BUILD_GCFLAGS = all=-trimpath=$(PWD)
8084
export GO_BUILD_FLAGS = -mod=vendor -buildvcs=false
81-
export GO_BUILD_LDFLAGS = -s -w -X '$(VERSION_PATH).version=$(VERSION)' -X '$(VERSION_PATH).gitCommit=$(GIT_COMMIT)' -extldflags "-static"
85+
export GO_BUILD_LDFLAGS = -s -w -X '$(VERSION_PATH).OLMVersion=$(VERSION)' -X '$(VERSION_PATH).GitCommit=$(GIT_COMMIT)' -extldflags "-static"
8286
export GO_BUILD_TAGS = json1
8387

8488
# GO_TEST flags are set with = to allow for re-evaluation of the variables
@@ -330,7 +334,6 @@ ifeq ($(PACKAGE_QUICKSTART), true)
330334
endif
331335

332336
.PHONY: release
333-
release: RELEASE_VERSION=v$(shell cat OLM_VERSION) #HELP Generate an OLM release (NOTE: before running release, bump the version in ./OLM_VERSION and push to master, then tag those builds in quay with the version in ./OLM_VERSION)
334337
release: pull-opm manifests # pull the opm image to get the digest
335338
@echo "Generating the $(RELEASE_VERSION) release"
336339
docker pull $(IMAGE_REPO):$(RELEASE_VERSION)

Diff for: OLM_VERSION

-1
This file was deleted.

0 commit comments

Comments
 (0)