@@ -2,11 +2,37 @@ MAIN_PACKAGE_PATH := ./cmd/asdf
2
2
TARGET_DIR := .
3
3
TARGET := asdf
4
4
5
- # Because this Makefile isn't used as part of the actual release binary build,
6
- # It sets FULL_VERSION to a dev version containing the SHA of the current
7
- # commit. If we ever use this Makefile to generate release binaries this code
8
- # will need to change.
9
- FULL_VERSION = "$(shell git rev-parse --short HEAD) -dev"
5
+ # Currently this Makefile isn't used as part of the actual release binary build,
6
+ # It sets FULL_VERSION to a correct dev version including the SHA of the current
7
+ # commit. This Makefile could be used to generate nightly release binaries.
8
+
9
+ # Set base version for dev build from previous tag
10
+ BASE_VERSION = $(shell git describe --tags --abbrev=0 2>/dev/null || echo "0.1.0")
11
+
12
+ # Get number of commits since the last tag so that it can be used to generate valid higher semver
13
+ COMMITS_SINCE_TAG = $(shell git rev-list $(BASE_VERSION ) .. --count 2>/dev/null || echo "0")
14
+
15
+ # Get the current commit hash (short); add hash as semver build label which is not used for version sorting precedence
16
+ GIT_HASH = $(shell git rev-parse --short HEAD)
17
+
18
+ # Determine final version:
19
+ ifeq ($(COMMITS_SINCE_TAG ) ,0)
20
+ # If exactly on a tag, use BASE_VERSION as-is
21
+ FULL_VERSION = "$(BASE_VERSION ) "
22
+ else
23
+ # Extract major, minor, patch components needed to generate final dev build version
24
+ MAJOR = $(shell echo $(BASE_VERSION ) | awk -F. '{print $$1}')
25
+ MINOR = $(shell echo $(BASE_VERSION ) | awk -F. '{print $$2}')
26
+ PATCH = $(shell echo $(BASE_VERSION ) | awk -F. '{print $$3}')
27
+
28
+ # Increment patch version for dev builds so that dev build version is always > than last tag version
29
+ DEV_PATCH = $(shell echo $$(($(PATCH ) + 1 ) ) )
30
+
31
+ # Construct full version for dev build
32
+ FULL_VERSION = "$(MAJOR ) .$(MINOR ) .$(DEV_PATCH ) -dev.$(COMMITS_SINCE_TAG ) +$(GIT_HASH ) "
33
+ endif
34
+
35
+ # Linker flags
10
36
LINKER_FLAGS = '-s -X main.version=${FULL_VERSION}'
11
37
12
38
# Not sure what the default location should be for builds
0 commit comments