Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added code to display version as commit hash #85

Merged
merged 10 commits into from
Jun 12, 2024
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.
ehearneRedHat marked this conversation as resolved.
Show resolved Hide resolved
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"
)
Loading