From 404860f262683c0a0024357a633a0ae124e94b53 Mon Sep 17 00:00:00 2001 From: mynk8 Date: Mon, 4 May 2026 19:06:59 +0530 Subject: [PATCH 1/2] fix: include commit in version output Signed-off-by: mynk8 --- Makefile | 13 +++++++++++-- cmd/cmd.go | 3 +++ cmd/version.go | 6 +++--- version/version.go | 7 ++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 11f799a..6b57b73 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,13 @@ WATCHER_NAME=watcher HOST_OS=$(shell go env GOOS) HOST_ARCH=$(shell go env GOARCH) +VERSION ?= $(shell git describe --tags --dirty --always 2>/dev/null || echo unknown) +COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) +LDFLAGS=-X ${PACKAGE}/version.Version=${VERSION} -X ${PACKAGE}/version.Commit=${COMMIT} .PHONY: build-local build-local: - go build -o ${DIST_DIR}/${BIN_NAME} + go build -ldflags "${LDFLAGS}" -o ${DIST_DIR}/${BIN_NAME} .PHONY: clean clean: @@ -25,6 +28,12 @@ build-binaries: make BIN_NAME=${CLI_NAME}-windows-amd64.exe GOOS=windows build-local make BIN_NAME=${CLI_NAME}-windows-386.exe GOOS=windows GOARCH=386 build-local +.PHONY: build-release +build-release: + $(eval RELEASE_VERSION := $(shell git describe --tags --exact-match 2>/dev/null)) + @test -n "${RELEASE_VERSION}" || (echo "build-release must be run from a git tag" && exit 1) + make VERSION=${RELEASE_VERSION} build-binaries + .PHONY: build-watcher build-watcher: - go build -o ${DIST_DIR}/${BIN_NAME}-${WATCHER_NAME} ${PACKAGE}/watcher \ No newline at end of file + go build -o ${DIST_DIR}/${BIN_NAME}-${WATCHER_NAME} ${PACKAGE}/watcher diff --git a/cmd/cmd.go b/cmd/cmd.go index 16df6b9..739fce3 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -19,6 +19,7 @@ import ( "github.com/microcks/microcks-cli/pkg/config" "github.com/microcks/microcks-cli/pkg/connectors" "github.com/microcks/microcks-cli/pkg/errors" + "github.com/microcks/microcks-cli/version" "github.com/spf13/cobra" ) @@ -29,6 +30,7 @@ func NewCommad() *cobra.Command { command := &cobra.Command{ Use: "microcks", Short: "A CLI tool for Microcks", + Version: version.Info(), SilenceUsage: true, Run: func(cmd *cobra.Command, args []string) { cmd.HelpFunc()(cmd, args) @@ -37,6 +39,7 @@ func NewCommad() *cobra.Command { HiddenDefaultCmd: true, }, } + command.SetVersionTemplate("{{.Version}}\n") command.AddCommand(NewImportCommand(&clientOpts)) command.AddCommand(NewImportDirCommand(&clientOpts)) diff --git a/cmd/version.go b/cmd/version.go index 6ce7163..d51a5bf 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -25,10 +25,10 @@ import ( func NewVersionCommand() *cobra.Command { var command = &cobra.Command{ Use: "version", - Short: "Print the version number of microkcs CLI", - Long: `Print the version number of microkcs CLI`, + Short: "Print the version number of Microcks CLI", + Long: `Print the version number of Microcks CLI`, Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("Microcks-CLI %s\n", version.Version) + fmt.Println(version.Info()) }, } diff --git a/version/version.go b/version/version.go index 48984dc..d007268 100644 --- a/version/version.go +++ b/version/version.go @@ -16,5 +16,10 @@ package version var ( - Version = "1.0.3" + Version = "unknown" + Commit = "unknown" ) + +func Info() string { + return "Microcks CLI " + Version + "\nCommit: " + Commit +} From 05b0144a01c44a67781355fe4d32d909a0ed76b9 Mon Sep 17 00:00:00 2001 From: mynk8 Date: Tue, 5 May 2026 18:01:18 +0530 Subject: [PATCH 2/2] chore: make build flags overridable Signed-off-by: mynk8 --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6b57b73..53546f6 100644 --- a/Makefile +++ b/Makefile @@ -7,13 +7,15 @@ WATCHER_NAME=watcher HOST_OS=$(shell go env GOOS) HOST_ARCH=$(shell go env GOARCH) +GO ?= go +BUILD_FLAGS ?= VERSION ?= $(shell git describe --tags --dirty --always 2>/dev/null || echo unknown) COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) LDFLAGS=-X ${PACKAGE}/version.Version=${VERSION} -X ${PACKAGE}/version.Commit=${COMMIT} .PHONY: build-local build-local: - go build -ldflags "${LDFLAGS}" -o ${DIST_DIR}/${BIN_NAME} + $(GO) build $(BUILD_FLAGS) -ldflags "${LDFLAGS}" -o ${DIST_DIR}/${BIN_NAME} .PHONY: clean clean: @@ -36,4 +38,4 @@ build-release: .PHONY: build-watcher build-watcher: - go build -o ${DIST_DIR}/${BIN_NAME}-${WATCHER_NAME} ${PACKAGE}/watcher + $(GO) build $(BUILD_FLAGS) -o ${DIST_DIR}/${BIN_NAME}-${WATCHER_NAME} ${PACKAGE}/watcher