Skip to content
Permalink
Browse files

build: use git tag as version if available

  • Loading branch information...
olt committed Jul 4, 2019
1 parent ccd5ed1 commit 0cd411a835a9444070685ecfd4d94ed6143e14e0
Showing with 14 additions and 14 deletions.
  1. +11 −4 Makefile
  2. +3 −10 version.go
@@ -7,8 +7,16 @@ DEPS:=$(GO_FILES) $(GOMAPNIK_CONFIG)

BUILD_DATE=$(shell date +%Y%m%d)
BUILD_REV=$(shell git rev-parse --short HEAD)
BUILD_VERSION=dev-$(BUILD_DATE)-$(BUILD_REV)
VERSION_LDFLAGS=-X github.com/omniscale/magnacarto.buildVersion=$(BUILD_VERSION)
BUILD_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
TAG=$(shell git name-rev --tags --name-only $(BUILD_REV))
ifeq ($(TAG),undefined)
BUILD_VERSION=$(BUILD_BRANCH)-$(BUILD_DATE)-$(BUILD_REV)
else
# use TAG but strip v of v1.2.3
BUILD_VERSION=$(TAG:v%=%)
endif

VERSION_LDFLAGS=-X github.com/omniscale/magnacarto.Version=$(BUILD_VERSION)

GO:=$(if $(shell go version |grep 'go1.5'),GO15VENDOREXPERIMENT=1,) go

@@ -43,8 +51,7 @@ cmds: build $(CMDS)
clean:
rm -f $(CMDS)

VERSION = $(shell ./$(firstword $(CMDS)) -version)
BIN_VERSION = $(VERSION)$(DISTRIBUTION)-$(uname_S)-$(uname_M)
BIN_VERSION = $(BUILD_VERSION)$(DISTRIBUTION)-$(uname_S)-$(uname_M)

dist: cmds
mkdir -p dist/
@@ -1,12 +1,5 @@
package magnacarto

var Version string

// buidVersion gets replaced while building with
// go build -ldflags "-X github.com/omniscale/magnacarto.buildVersion 1234"
var buildVersion string

func init() {
Version = "0.1"
Version += buildVersion
}
// Version gets replaced while building with
// go build -ldflags "-X github.com/omniscale/magnacarto.Version 1.2.3"
var Version = "0.0.0-dev"

0 comments on commit 0cd411a

Please sign in to comment.
You can’t perform that action at this time.