diff --git a/Makefile b/Makefile index 1d3c7f9..c906b02 100644 --- a/Makefile +++ b/Makefile @@ -1,36 +1,39 @@ -all: generate lint test +all: build lint test -VERSION=0.0.1 - -include .bingo/Variables.mk +VERSION=0.0.2 KORREL8RCLI=cmd/korrel8rcli/korrel8rcli +VERSION_TXT=pkg/build/version.txt SWAGGER_CLIENT=pkg/swagger SWAGGER_SPEC=korrel8r-swagger.json GOCOVERDIR=cmd/korrel8rcli/covdata -clean: - rm -rf $(GOCOVERDIR) $(KORREL8RCLI) $(SWAGGER_CLIENT) $(SWAGGER_SPEC) - -generate: $(SWAGGER_CLIENT) +include .bingo/Variables.mk build: $(KORREL8RCLI) -$(KORREL8RCLI): $(shell find -name *.go) generate - @mkdir -p $(dir $@) - go build -cover -o $@ ./cmd/korrel8rcli - lint: $(GOLANGCI_LINT) $(GOLANGCI_LINT) run ./... -test: $(KORREL8RCLI) $(KORREL8R) $(TEST_ENV) +test: $(KORREL8RCLI) $(KORREL8R) KORREL8R=$(KORREL8R) go test -cover -race ./... @echo -e "\\nAccumulated coverage from main_test" go tool covdata percent -i $(GOCOVERDIR) -release: all - hack/tag-release.sh $(VERSION) +clean: + rm -rf $(GOCOVERDIR) $(KORREL8RCLI) $(SWAGGER_CLIENT) $(SWAGGER_SPEC) + +ifneq ($(VERSION),$(file <$(VERSION_TXT))) +.PHONY: $(VERSION_TXT) # Force update if VERSION_TXT does not match $(VERSION) +endif +$(VERSION_TXT): + echo $(VERSION) > $@ + +$(KORREL8RCLI): $(VERSION_TXT) $(SWAGGER_CLIENT) $(shell find -name *.go) + @mkdir -p $(dir $@) + @go mod tidy + go build -cover -o $@ ./cmd/korrel8rcli $(SWAGGER_SPEC): $(KORREL8R) $(KORREL8R) web --spec $@ @@ -39,3 +42,6 @@ $(SWAGGER_CLIENT): $(SWAGGER_SPEC) $(SWAGGER) ## Generate client packages. @mkdir -p $@ cd $@ && $(SWAGGER) generate -q client -f $(abspath $(SWAGGER_SPEC)) && go mod tidy touch $@ + +release: all + hack/tag-release.sh $(VERSION) diff --git a/cmd/korrel8rcli/main.go b/cmd/korrel8rcli/main.go index 3686425..4c727e0 100644 --- a/cmd/korrel8rcli/main.go +++ b/cmd/korrel8rcli/main.go @@ -11,14 +11,16 @@ import ( "os" httptransport "github.com/go-openapi/runtime/client" + "github.com/korrel8r/client/pkg/build" "github.com/korrel8r/client/pkg/swagger/client" "github.com/spf13/cobra" ) var ( rootCmd = &cobra.Command{ - Use: "korrel8rcli COMMAND", - Short: "REST client for a remote korrel8r server.", + Use: "korrel8rcli COMMAND", + Short: "REST client for a remote korrel8r server.", + Version: build.Version, } // Global Flags diff --git a/go.sum b/go.sum index 9a1dcc2..5e6a87c 100644 --- a/go.sum +++ b/go.sum @@ -114,8 +114,8 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= -github.com/korrel8r/korrel8r v0.6.5 h1:PVxgYoplwDcxwqx4EaQVly9JK1uq7uBrHokq5+uEoyU= -github.com/korrel8r/korrel8r v0.6.5/go.mod h1:2hx8gEgyDXSbDYqxlqOUxlFnxfxZ2IYk5Ts1fL8Ye28= +github.com/korrel8r/korrel8r v0.6.5 h1:1n+lI8cPN5YX1Vyn0wl+ujpIdl5wOOtgN2PLUSL/uzo= +github.com/korrel8r/korrel8r v0.6.5/go.mod h1:ttC8wLIyHtU1yjDiIpHEjt/BWllSk09ZUk7KLGgyzLU= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= diff --git a/pkg/build/build.go b/pkg/build/build.go new file mode 100644 index 0000000..095ed03 --- /dev/null +++ b/pkg/build/build.go @@ -0,0 +1,9 @@ +package build + +import "strings" + +var ( + version string //+embed:version.txt + // Version of the current build, a semver string. + Version = strings.TrimSpace(version) +) diff --git a/pkg/build/version.txt b/pkg/build/version.txt new file mode 100644 index 0000000..4e379d2 --- /dev/null +++ b/pkg/build/version.txt @@ -0,0 +1 @@ +0.0.2