diff --git a/Makefile b/Makefile index 92c750a..073034d 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,14 @@ -include .env export +# Derive the version from git so `make build` stamps the binary. Falls back to +# the commit hash if no tag is reachable, and appends "-dirty" for uncommitted changes. +# When git is unavailable (e.g. a source tarball), VERSION is empty and we omit the +# ldflag entirely so the in-code default (0.0.0-DEV) is preserved. +VERSION := $(shell git describe --tags --always --dirty 2>/dev/null) +VERSION_PKG := github.com/temporalio/cloud-cli/temporalcloudcli +LDFLAGS := $(if $(VERSION),-X $(VERSION_PKG).Version=$(VERSION)) + all: gen build mocks test # we need to install gen-commands directly because gen-commands does not have its @@ -18,7 +26,7 @@ gen: install gen-commands -input ./temporalcloudcli/commands.yml -pkg temporalcloudcli > ./temporalcloudcli/commands.gen.go build: - go build ./cmd/temporal-cloud + go build -ldflags "$(LDFLAGS)" ./cmd/temporal-cloud test-integration: go test -tags=integration ./... diff --git a/README.md b/README.md index 6aeb20d..550946f 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Plugin for the Temporal command-line interface to work with [Temporal Cloud](htt 1. Install [Go](https://go.dev/doc/install) (check [go.mod](./go.mod) for the version). 2. Clone this repository. -3. From the cloned directory, run `make build` (or `go build ./cmd/temporal-cloud`). +3. From the cloned directory, run `make build`. The executable will be at `temporal-cloud` (`temporal-cloud.exe` for Windows). Add it to your `PATH` so the `temporal` CLI can discover it.