From d198cc865a2bfa0fed621d0238280e17502deaaf Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Mon, 10 Jun 2024 10:21:22 +0100 Subject: [PATCH] changed version to consequent dev version + added git dirty with updated make target --- Makefile | 29 +++++++++++++++++++++++------ version/version.go | 11 ++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 1aa17b3..9948b0f 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,6 @@ MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH))) GO ?= go KUADRANT_NAMESPACE=kuadrant-system -VERSION := $(shell git rev-parse --short=7 HEAD) all: help @@ -56,11 +55,29 @@ test: clean-cov fmt vet $(GINKGO) ## install: Build and install kuadrantctl binary ($GOBIN or GOPATH/bin) .PHONY : install install: fmt vet -ifneq ($(VERSION),) - GOBIN=$(PROJECT_PATH)/bin $(GO) install -ldflags "-X 'github.com/kuadrant/kuadrantctl/version.Version=dev - $(VERSION)'" -else - GOBIN=$(PROJECT_PATH)/bin $(GO) install -endif + @set -e; \ + GIT_SHA=$$(git rev-parse --short=7 HEAD 2>/dev/null) || { \ + GIT_HASH=$${GITHUB_SHA:-NO_SHA}; \ + IS_DIRTY=false; \ + }; \ + if [ -z "$$GIT_HASH" ]; then \ + GIT_DIRTY=$$(git diff --stat); \ + if [ -n "$$GIT_DIRTY" ]; then \ + GIT_HASH=$${GIT_SHA}-dirty; \ + IS_DIRTY=true; \ + else \ + GIT_HASH=$${GIT_SHA}; \ + IS_DIRTY=false; \ + fi; \ + fi; \ + LDFLAGS="-X 'github.com/kuadrant/kuadrantctl/version.GitHash=$$GIT_HASH'"; \ + if [ "$$IS_DIRTY" = true ]; then \ + LDFLAGS="$$LDFLAGS -X 'github.com/kuadrant/kuadrantctl/version.GitDirty=true'"; \ + else \ + LDFLAGS="$$LDFLAGS -X 'github.com/kuadrant/kuadrantctl/version.GitDirty=false'"; \ + fi; \ + GOBIN=$(PROJECT_PATH)/bin $(GO) install -ldflags "$$LDFLAGS"; + .PHONY: prepare-local-cluster prepare-local-cluster: $(KIND) ## Deploy locally kuadrant operator from the current code diff --git a/version/version.go b/version/version.go index ed1f230..9b32a21 100644 --- a/version/version.go +++ b/version/version.go @@ -15,6 +15,15 @@ limitations under the License. */ package version +import "fmt" + var ( - Version = "v0.0.0" + // This variable shows the commit hash of the repo so they can confirm they are on latest or specific version of the branch. + GitHash string + // This variable is dependent on what the current release is e.g. if it is v0.2.3 then this variable, outside of releases, will be v0.2.4-dev . + Version = "v0.2.4-dev" ) + +func init() { + Version = fmt.Sprintf("%s (%s)", Version, GitHash) +}