From c76b96ed36dbc59d6f9b087d5f2d5ca7ec335491 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 | 9 +++++---- version/version.go | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 1aa17b3..5d2917d 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ 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) +GIT_HASH := $(shell git rev-parse --short=7 HEAD) +GIT_DIRTY := $(shell git diff --stat) all: help @@ -56,9 +57,9 @@ 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 +ifneq ($(GIT_HASH),$(GIT_DIRTY)) + GOBIN=$(PROJECT_PATH)/bin $(GO) install -ldflags "-X 'github.com/kuadrant/kuadrantctl/version.GitDirty=$(GIT_DIRTY)' -X 'github.com/kuadrant/kuadrantctl/version.GitHash=$(GIT_HASH)'" +else GOBIN=$(PROJECT_PATH)/bin $(GO) install endif diff --git a/version/version.go b/version/version.go index ed1f230..05c46e3 100644 --- a/version/version.go +++ b/version/version.go @@ -16,5 +16,18 @@ limitations under the License. package version var ( - Version = "v0.0.0" + // This variable shows the user any additional changes to files made that aren't on the branch. + GitDirty string + // 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() { + if GitDirty != "" && GitHash != "" { + Version += " (" + GitHash + " - " + GitDirty + ")" + } else if GitDirty == "" { + Version += " (" + GitHash + ")" + } +}