Skip to content

Commit

Permalink
Merge pull request #85 from Kuadrant/commit-hash-version
Browse files Browse the repository at this point in the history
added code to display version as commit hash
  • Loading branch information
ehearneRedHat authored Jun 12, 2024
2 parents 983bde5 + a44d61c commit 64f6301
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
Expand Down
5 changes: 4 additions & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit 64f6301

Please sign in to comment.