diff --git a/Makefile b/Makefile index e84e607..0ca189f 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,21 @@ test: clean-cov fmt vet $(GINKGO) ## install: Build and install kuadrantctl binary ($GOBIN or GOPATH/bin) .PHONY : install install: fmt vet - GOBIN=$(PROJECT_PATH)/bin $(GO) install + @set -e; \ + GIT_SHA=$$(git rev-parse --short=7 HEAD 2>/dev/null) || { \ + GIT_HASH=$${GITHUB_SHA:-NO_SHA}; \ + }; \ + if [ -z "$$GIT_HASH" ]; then \ + GIT_DIRTY=$$(git diff --stat); \ + if [ -n "$$GIT_DIRTY" ]; then \ + GIT_HASH=$${GIT_SHA}-dirty; \ + else \ + GIT_HASH=$${GIT_SHA}; \ + fi; \ + fi; \ + LDFLAGS="-X 'github.com/kuadrant/kuadrantctl/version.GitHash=$$GIT_HASH'"; \ + 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/README.md b/README.md index ee4431f..e151e59 100644 --- a/README.md +++ b/README.md @@ -15,13 +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`. 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. + +It is possible to use the make target `install` to compile from source. From root of the repository, run ```bash -go install github.com/kuadrant/kuadrantctl@latest +make install ``` -This command will compile `kuadrantctl` and install the binary executable in `$GOBIN` (defaulting to `$GOPATH/bin`). +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 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 ed1f230..e650ae7 100644 --- a/version/version.go +++ b/version/version.go @@ -16,5 +16,8 @@ limitations under the License. package version 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" )