-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.versioning
66 lines (59 loc) · 1.88 KB
/
Makefile.versioning
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (C) 2016 wikiwi.io
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.
# VERSION contains the project verison e.g. 0.1.0-alpha.1
VERSION := $(shell grep -E -o "[0-9]+\.[0-9]+\.[0-9]+[^\"+]*" pkg/version/version.go)
# VERSION_MINOR contains the project version up to the minor value e.g. v0.1
VERSION_MINOR := $(shell echo ${VERSION} | grep -E -o "[0-9]+\.[0-9]+")
# VERSION_STAGE contains the project version stage e.g. alpha
VERSION_STAGE := $(shell echo ${VERSION} | grep -E -o "(pre-alpha|alpha|beta|rc)")
# Extract git Information of current commit.
GIT_SHA := $(shell ${GIT} rev-parse HEAD)
GIT_SHA_SHORT := $(shell ${GIT} rev-parse --short HEAD)
GIT_SHA_MASTER := $(shell ${GIT} rev-parse ${MASTER_BRANCH})
GIT_TAG := $(shell ${GIT} tag -l --contains HEAD | head -n1)
GIT_BRANCH := $(shell ${GIT} branch | grep -E '^* ' | cut -c3- )
IS_DIRTY := $(shell ${GIT} status --porcelain)
ifndef IS_DIRTY
ifeq (${GIT_SHA},${GIT_SHA_MASTER})
IS_CANARY := true
endif
ifeq (${GIT_TAG},${VERSION})
IS_RELEASE := true
endif
endif
# Set build reference.
ifdef IS_DIRTY
BUILD_REF := ${GIT_SHA_SHORT}-dirty
else
BUILD_REF := ${GIT_SHA_SHORT}
endif
# BUILD_VERSION will be compiled into the projects binaries.
ifdef IS_RELEASE
BUILD_VERSION ?= ${VERSION}
else
BUILD_VERSION ?= ${VERSION}+${BUILD_REF}
endif
# Set image tags.
TAGS :=
ifeq (${IS_CANARY},true)
TAGS := canary ${TAGS}
ifeq (${LATEST_VERSION},canary)
TAGS := latest ${TAGS}
endif
endif
ifdef IS_RELEASE
TAGS := ${VERSION} ${TAGS}
ifeq (${LATEST_VERSION},${VERSION})
TAGS := latest ${TAGS}
endif
ifdef VERSION_STAGE
TAGS := ${VERSION_MINOR}-${VERSION_STAGE} ${TAGS}
else
TAGS := ${VERSION_MINOR} ${TAGS}
ifeq (${LATEST_VERSION},${VERSION_MINOR})
TAGS := latest ${TAGS}
endif
endif
endif