-
Notifications
You must be signed in to change notification settings - Fork 11
/
versioning.mk
44 lines (41 loc) · 1.46 KB
/
versioning.mk
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
VERSION_FILE ?= VERSION
# check if git is available
ifeq ($(shell which git),)
$(warning git is not available, binaries will not include git SHA)
GIT_SHA :=
GIT_TREE_STATE :=
GIT_TAG :=
VERSION_SUFFIX := unknown
else
GIT_SHA := $(shell git rev-parse --short HEAD)
# Tree state is "dirty" if there are uncommitted changes, untracked files are ignored
GIT_TREE_STATE := $(shell test -n "`git status --porcelain --untracked-files=no`" && echo "dirty" || echo "clean")
# Empty string if we are not building a tag
GIT_TAG := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
ifeq ($(GIT_TREE_STATE),dirty)
VERSION_SUFFIX := $(GIT_SHA).dirty
else
VERSION_SUFFIX := $(GIT_SHA)
endif
endif
# if building a tag or VERSION is set, set RELEASE_STATUS to "released"
ifdef VERSION
RELEASE_STATUS := released
else ifneq ($(GIT_TAG),)
RELEASE_STATUS := released
else
RELEASE_STATUS := unreleased
endif
ifndef VERSION
VERSION := $(shell head -n 1 $(VERSION_FILE))
DOCKER_IMG_VERSION := $(VERSION)-$(VERSION_SUFFIX)
else
DOCKER_IMG_VERSION := $(VERSION)
endif
version-info:
@echo "===> Version information <==="
@echo "VERSION: $(VERSION)"
@echo "GIT_SHA: $(GIT_SHA)"
@echo "GIT_TREE_STATE: $(GIT_TREE_STATE)"
@echo "RELEASE_STATUS: $(RELEASE_STATUS)"
@echo "DOCKER_IMG_VERSION: $(DOCKER_IMG_VERSION)"