[Makefile] Introduce _ensure-current-version to ensure version tags

Peter Dave Hello 2017-04-09 10:51:54 +08:00
parent 65aedc105a
commit d80686c7cd
1 changed files with 9 additions and 1 deletions

View File

@ -55,6 +55,14 @@ ifndef TAG
$(error Please invoke with `make TAG=<new-version> release`, where <new-version> is either an increment specifier (patch, minor, major, prepatch, preminor, premajor, prerelease), or an explicit major.minor.patch version number) $(error Please invoke with `make TAG=<new-version> release`, where <new-version> is either an increment specifier (patch, minor, major, prepatch, preminor, premajor, prerelease), or an explicit major.minor.patch version number)
endif endif
# Ensures there are version tags in repository
.PHONY: _ensure-current-version
_ensure-current-version:
ifeq ($(shell git tag),$(printf ''))
@git fetch --tags
endif
# Ensures that the git workspace is clean. # Ensures that the git workspace is clean.
.PHONY: _ensure-clean .PHONY: _ensure-clean
_ensure-clean: _ensure-clean:
@ -62,7 +70,7 @@ _ensure-clean:
# Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`. # Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`.
.PHONY: release .PHONY: release
release: _ensure-tag _ensure-clean release: _ensure-tag _ensure-clean _ensure-current-version
@old_ver=`git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*'` || { echo "Failed to determine current version." >&2; exit 1; }; old_ver=$${old_ver#v}; \ @old_ver=`git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*'` || { echo "Failed to determine current version." >&2; exit 1; }; old_ver=$${old_ver#v}; \
new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \ new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \
if printf "$$new_ver" | grep -q '^[0-9]'; then \ if printf "$$new_ver" | grep -q '^[0-9]'; then \