Skip to content

Commit

Permalink
derive version at "make build" time from git tags
Browse files Browse the repository at this point in the history
When using "go get" or "go install", the packet-cli version will be
"devel".  When using build artifacts, or when running `make`, the
version will be derived from the git tag (and latest commit sha).

Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Jul 21, 2020
1 parent 8a57c21 commit 56cd8d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ K := $(foreach exec,$(EXECUTABLES),\

ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

BINARY=packet
VERSION=0.0.5
PACKAGE_NAME?=github.com/packethost/packet-cli
BINARY?=packet
GIT_VERSION?=$(shell git log -1 --format="%h")
VERSION?=$(GIT_VERSION)
RELEASE_TAG?=$(shell git tag --points-at HEAD)
ifneq (,$(RELEASE_TAG))
VERSION:=$(RELEASE_TAG)-$(VERSION)
endif

BUILD=`git rev-parse --short HEAD`
PLATFORMS=darwin linux windows freebsd
ARCHITECTURES=amd64 arm64
PLATFORMS?=darwin linux windows freebsd
ARCHITECTURES?=amd64 arm64

# Setup linker flags option for build that interoperate with variable names in src code
LDFLAGS=-ldflags "-X github.com/packethost/packet-cli/cmd.Version=${VERSION} -X github.com/packethost/packet-cli/cmd.Build=${BUILD}"
LDFLAGS?=-ldflags "-X $(PACKAGE_NAME)/cmd.Version=$(VERSION) -X $(PACKAGE_NAME)/cmd.Build=$(BUILD)"

default: generate-docs
go fmt ./...
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Cli struct {

// VERSION build
var (
Version string = "0.0.7"
Version string = "devel"
)

// NewCli struct
Expand Down

0 comments on commit 56cd8d9

Please sign in to comment.