From 2f3eabc3ca81db723ab178d7261a9ee17bd8b38c Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sun, 12 Apr 2020 14:37:49 +0200 Subject: [PATCH] Annotate git hash and time in displayed version --- Makefile | 11 ++++++++--- cmd/root.go | 10 +++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 8952a902..aef1487b 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ + +# go tool nm ./luet | grep Commit +LDFLAGS += -X "github.com/mudler/luet/cmd.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')" +LDFLAGS += -X "github.com/mudler/luet/cmd.BuildCommit=$(shell git rev-parse HEAD)" + NAME ?= luet PACKAGE_NAME ?= $(NAME) PACKAGE_CONFLICT ?= $(PACKAGE_NAME)-beta @@ -59,7 +64,7 @@ deps: .PHONY: build build: - CGO_ENABLED=0 go build + CGO_ENABLED=0 go build -ldflags '$(LDFLAGS)' .PHONY: image image: @@ -67,7 +72,7 @@ image: .PHONY: gox-build gox-build: - CGO_ENABLED=0 gox $(BUILD_PLATFORMS) -output="release/$(NAME)-$(VERSION)-{{.OS}}-{{.Arch}}" + CGO_ENABLED=0 gox $(BUILD_PLATFORMS) -ldflags '$(LDFLAGS)' -output="release/$(NAME)-$(VERSION)-{{.OS}}-{{.Arch}}" .PHONY: lint lint: @@ -85,4 +90,4 @@ test-docker: .PHONY: multiarch-build multiarch-build: - gox $(BUILD_PLATFORMS) -output="release/$(NAME)-$(VERSION)-{{.OS}}-{{.Arch}}" + gox $(BUILD_PLATFORMS) -ldflags '$(LDFLAGS)' -output="release/$(NAME)-$(VERSION)-{{.OS}}-{{.Arch}}" diff --git a/cmd/root.go b/cmd/root.go index 4b3835db..59521523 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -42,12 +42,20 @@ const ( LuetEnvPrefix = "LUET" ) +// Build time and commit information. +// +// ⚠️ WARNING: should only be set by "-ldflags". +var ( + BuildTime string + BuildCommit string +) + // RootCmd represents the base command when called without any subcommands var RootCmd = &cobra.Command{ Use: "luet", Short: "Package manager for the XXth century!", Long: `Package manager which uses containers to build packages`, - Version: LuetCLIVersion, + Version: fmt.Sprintf("%s-g%s %s", LuetCLIVersion, BuildCommit, BuildTime), PersistentPreRun: func(cmd *cobra.Command, args []string) { err := LoadConfig(config.LuetCfg) if err != nil {