From 5e6b5dc5409215c99fd9147a62c57b9af06f3740 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 9 Jan 2024 13:09:53 -0500 Subject: [PATCH] Embed version string from git description --- Makefile | 6 ++++-- cmd/root.go | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index f1b1a25..f382b97 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,13 @@ +VERSION := $(shell git describe --always --dirty --tags) + CGO_ENABLED = 0 # Strip binaries by default to make them smaller. -GO_LDFLAGS = -s -w +GO_LDFLAGS = -s -w -X github.com/rstudio/rskey/cmd.Version=$(VERSION) # Using the 'netgo' tag opts into the native implementation and allows for # static binaries. GO_BUILD_ARGS = -v -tags "netgo" -trimpath -GOPATH = `go env GOPATH` +GOPATH = $(shell go env GOPATH) ADDLICENSE = $(GOPATH)/bin/addlicense ADDLICENSE_ARGS = -v -s=only -l=apache -c "RStudio, PBC" -ignore 'coverage*' -ignore '.github/**' -ignore '.goreleaser.yaml' NOTICETOOL = $(GOPATH)/bin/go-licence-detector diff --git a/cmd/root.go b/cmd/root.go index 96be1d2..4b14a4a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -9,9 +9,14 @@ import ( "github.com/spf13/cobra" ) +var ( + Version = "???" +) + var rootCmd = &cobra.Command{ - Use: "rskey", - Short: "Manage keys and secrets for RStudio Connect and Package Manager", + Use: "rskey", + Short: "Manage keys and secrets for RStudio Connect and Package Manager", + Version: Version, } // Execute runs the rskey command. On error it will call os.Exit.