From 337953d1afb815536365dc3c7dff39c1fd13eb81 Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Thu, 23 May 2024 09:26:04 +0100 Subject: [PATCH 1/9] added make target for adding git commit hash as version --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 2a23925..0845932 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ test: fmt vet $(GINKGO) ## install: Build and install kuadrantctl binary ($GOBIN or GOPATH/bin) .PHONY : install install: fmt vet + $(MAKE) update-version GOBIN=$(PROJECT_PATH)/bin $(GO) install .PHONY: prepare-local-cluster @@ -74,5 +75,10 @@ fmt: vet: $(GO) vet ./... +.PHONY: update-version +update-version: + @commit_hash=$$(git rev-parse --short=7 HEAD); \ + sed -i.bak 's/Version = "v0.0.0"/Version = "dev - '$${commit_hash}'"/' version/version.go && rm version/version.go.bak + # Include last to avoid changing MAKEFILE_LIST used above include ./make/*.mk From 6252febad84130f52e9794fc131aaad29474db7f Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Thu, 23 May 2024 09:35:06 +0100 Subject: [PATCH 2/9] added additional make target instructions to README --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ee4431f..7b2d3fa 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ### Compiling from Source -If you prefer to compile from source or are contributing to the project, you can install `kuadrantctl` using `go install`. This method requires Golang 1.21 or newer. +If you prefer to compile from source or are contributing to the project, you can install `kuadrantctl` using `go install` or `make install`. This method requires Golang 1.21 or newer. ```bash go install github.com/kuadrant/kuadrantctl@latest @@ -23,6 +23,14 @@ go install github.com/kuadrant/kuadrantctl@latest This command will compile `kuadrantctl` and install the binary executable in `$GOBIN` (defaulting to `$GOPATH/bin`). +It is also possible to use the make target `install` to compile from source. From root of the repository, run + +```bash +make install +``` + +This will compile `kuadrantctl` and install it in the `bin` directory at root of directory. It will also ensure the correct version of the binary is displayed, rather than `v0.0.0` . It can be ran using `./bin/kuadrantctl` . + ## Usage Below is a high-level overview of its commands, along with links to detailed documentation for more complex commands. From 00b9b0100f407568212e58306bc13b59c4714ff5 Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Thu, 23 May 2024 10:57:05 +0100 Subject: [PATCH 3/9] set the version during build --- Makefile | 9 ++------- version/version.go | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 0845932..d4ee413 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ 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 @@ -41,8 +42,7 @@ test: fmt vet $(GINKGO) ## install: Build and install kuadrantctl binary ($GOBIN or GOPATH/bin) .PHONY : install install: fmt vet - $(MAKE) update-version - GOBIN=$(PROJECT_PATH)/bin $(GO) install + GOBIN=$(PROJECT_PATH)/bin $(GO) install -ldflags "-X 'github.com/kuadrant/kuadrantctl/version.Version=dev - $(VERSION)'" .PHONY: prepare-local-cluster prepare-local-cluster: $(KIND) ## Deploy locally kuadrant operator from the current code @@ -75,10 +75,5 @@ fmt: vet: $(GO) vet ./... -.PHONY: update-version -update-version: - @commit_hash=$$(git rev-parse --short=7 HEAD); \ - sed -i.bak 's/Version = "v0.0.0"/Version = "dev - '$${commit_hash}'"/' version/version.go && rm version/version.go.bak - # Include last to avoid changing MAKEFILE_LIST used above include ./make/*.mk diff --git a/version/version.go b/version/version.go index ed1f230..68e6100 100644 --- a/version/version.go +++ b/version/version.go @@ -16,5 +16,5 @@ limitations under the License. package version var ( - Version = "v0.0.0" + Version string ) From 1dac73e2f9cb68885c5efe6bafb1cc2b701c42e5 Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Thu, 30 May 2024 11:59:54 +0100 Subject: [PATCH 4/9] fixed make target bug + added default value for version --- Makefile | 4 ++++ version/version.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d4ee413..3433034 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,11 @@ test: 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 .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 68e6100..ed1f230 100644 --- a/version/version.go +++ b/version/version.go @@ -16,5 +16,5 @@ limitations under the License. package version var ( - Version string + Version = "v0.0.0" ) From d198cc865a2bfa0fed621d0238280e17502deaaf Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Mon, 10 Jun 2024 10:21:22 +0100 Subject: [PATCH 5/9] 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) +} From b633b72ba1a6d7b33d0685288b1c63dd93009687 Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Wed, 12 Jun 2024 08:55:33 +0100 Subject: [PATCH 6/9] removed unnecessary ldflag for git dirty --- Makefile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Makefile b/Makefile index 9948b0f..8aadbff 100644 --- a/Makefile +++ b/Makefile @@ -71,11 +71,6 @@ install: fmt vet 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"; From b83fa8f6d3fd7289b5815d55d942786cec8dcf25 Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Wed, 12 Jun 2024 09:01:04 +0100 Subject: [PATCH 7/9] removed kuadrant namespace variable from makefile --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 8aadbff..488a49d 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ SHELL := /bin/bash MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) PROJECT_PATH := $(patsubst %/,%,$(dir $(MKFILE_PATH))) GO ?= go -KUADRANT_NAMESPACE=kuadrant-system all: help From d8c9979cacffcd7eee88bd030574933d368625e3 Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Wed, 12 Jun 2024 09:04:23 +0100 Subject: [PATCH 8/9] removed init() and instead print version in cmd/version.go --- cmd/version.go | 2 +- version/version.go | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index 115b2d0..9390f08 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -20,7 +20,7 @@ func versionCommand() *cobra.Command { return err } - fmt.Println("kuadrantctl", version.Version) + fmt.Printf("kuadrantctl %s (%s)\n", version.Version, version.GitHash) return nil }, } diff --git a/version/version.go b/version/version.go index 9b32a21..e650ae7 100644 --- a/version/version.go +++ b/version/version.go @@ -15,15 +15,9 @@ limitations under the License. */ package version -import "fmt" - var ( // 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) -} From a44d61c3b2ad5ca31920e9416e1304378c5131d1 Mon Sep 17 00:00:00 2001 From: ehearneredhat Date: Wed, 12 Jun 2024 11:37:13 +0100 Subject: [PATCH 9/9] removed redundant references --- Makefile | 3 --- README.md | 12 +++--------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 488a49d..0ca189f 100644 --- a/Makefile +++ b/Makefile @@ -57,16 +57,13 @@ install: fmt vet @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'"; \ diff --git a/README.md b/README.md index 7b2d3fa..e151e59 100644 --- a/README.md +++ b/README.md @@ -15,21 +15,15 @@ ### Compiling from Source -If you prefer to compile from source or are contributing to the project, you can install `kuadrantctl` using `go install` or `make install`. This method requires Golang 1.21 or newer. +If you prefer to compile from source or are contributing to the project, you can install `kuadrantctl` using `make install`. This method requires Golang 1.21 or newer. -```bash -go install github.com/kuadrant/kuadrantctl@latest -``` - -This command will compile `kuadrantctl` and install the binary executable in `$GOBIN` (defaulting to `$GOPATH/bin`). - -It is also possible to use the make target `install` to compile from source. From root of the repository, run +It is possible to use the make target `install` to compile from source. From root of the repository, run ```bash make install ``` -This will compile `kuadrantctl` and install it in the `bin` directory at root of directory. It will also ensure the correct version of the binary is displayed, rather than `v0.0.0` . It can be ran using `./bin/kuadrantctl` . +This will compile `kuadrantctl` and install it in the `bin` directory at root of directory. It will also ensure the correct version of the binary is displayed . It can be ran using `./bin/kuadrantctl` . ## Usage