123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- PROJECT_NAME ?= project
- # versioning
- BUMP_VERSION_CONFIG ?= .bumpversion.cfg
- # allow missing "patch" number
- BUMP_VERSION_PARSE_REGEX = (?P<major>\d+)\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?
- CURRENT_VERSION_FILE ?= VERSION
- DIR_RELEASE_ARCHIVES ?= .
- RELEASE_TAR_COMPRESSION_BIN = gzip
- ifeq ($(RELEASE_TAR_COMPRESSION_BIN),gzip)
- RELEASE_TAR_COMPRESSION_EXTENSION = gz
- else ifeq ($(RELEASE_TAR_COMPRESSION_BIN),bzip2)
- RELEASE_TAR_COMPRESSION_EXTENSION = bz2
- else ifeq ($(RELEASE_TAR_COMPRESSION_BIN),xz)
- RELEASE_TAR_COMPRESSION_EXTENSION = xz
- else
- $(error Invalid RELEASE_TAR_COMPRESSION specified: should be one of gzip / bzip2 / xz)
- endif
- RELEASE_TAR_FILENAME = $(DIR_RELEASE_ARCHIVES)/$(PROJECT_NAME)-$(call get_current_version).tar.$(RELEASE_TAR_COMPRESSION_EXTENSION)
- RELEASE_TAR_SIGN_FILENAME = $(RELEASE_TAR_FILENAME).asc
- RELEASE_TAR_HASH_FUNC ?= sha256sum
- RELEASE_TAR_HASH_FILENAME = $(RELEASE_TAR_FILENAME).$(RELEASE_TAR_HASH_FUNC)
- IS_VERSION_WITH_BUMPVERSION = $(wildcard $(BUMP_VERSION_CONFIG))
- IS_VERSION_WITH_GIT = $(shell git rev-parse --is-inside-work-tree >/dev/null 2>&1 && echo 1 || true)
- IS_VERSION_WITH_DEB = $(wildcard debian/changelog)
- IS_VERSION_WITH_NPM = $(wildcard package.json)
- # assemble the list of files to be committed during "make release-*"
- BUMP_VERSION_FILES ?= $(BUMP_VERSION_CONFIG)
- ifneq ($(IS_VERSION_WITH_BUMPVERSION),)
- BUMP_VERSION_FILES += $(shell sed -n 's/^\[bumpversion:file:\(.*\)\]$$/\1/p' "$(BUMP_VERSION_CONFIG)")
- else
- BUMP_VERSION_FILES =
- endif
- ifneq ($(IS_VERSION_WITH_DEB),)
- BUMP_VERSION_FILES += debian/changelog
- endif
- ifneq "$(IS_VERSION_WITH_NPM)" ""
- BUMP_VERSION_FILES += package.json
- ifneq "$(wildcard package-lock.json)" ""
- BUMP_VERSION_FILES += package-lock.json
- endif
- endif
- define IS_RELEASE_CURRENT_COMMIT_TEST =
- [ "$$(git show -s --format=%H "v$(call get_current_version)^{commit}" --)" = "$$(git show -s --format=%H)" ]
- endef
- get_current_version = $(shell if ! cut -f 1-3 -d . "$(CURRENT_VERSION_FILE)" 2>/dev/null; then echo >&2 "Missing '$(CURRENT_VERSION_FILE)' file (see variable 'CURRENT_VERSION_FILE)'"; echo "unknown"; fi)
- .PHONY: help
- help: help-release
- .PHONY: help-release
- help-release:
- @echo "Release-related packaging targets:"
- @echo " release-major"
- @echo " release-minor"
- @echo " release-patch"
- @echo " release-undo"
- @echo " release-push"
- @echo " release-tar"
- @echo " release-tar-sign"
- @echo
- release-major: VERSION_BUMP=major
- release-minor: VERSION_BUMP=minor
- release-patch: VERSION_BUMP=patch
- .PHONY: release-major release-minor release-patch
- release-major release-minor release-patch: release-generic
- .PHONY: release-generic
- # prevent duplicate tags for successive commits
- release-generic:: | release-check-current-commit-is-not-release
- ifneq ($(IS_VERSION_WITH_BUMPVERSION),)
- release-generic:: | release-bumpversion
- endif
- ifneq ($(IS_VERSION_WITH_DEB),)
- release-generic:: | release-debchange
- endif
- # take care for the ordering: 'release-git' needs to run before '-debchange' and '-bumpversion'
- ifneq ($(IS_VERSION_WITH_GIT),)
- release-generic:: release-git
- endif
- ifneq "$(IS_VERSION_WITH_NPM)" ""
- release-generic:: release-npm
- # ensure that "release-git" is executed after "release-npm": package.json has to be updated in time
- release-git: release-npm
- endif
- .PHONY: release-check-current-commit-is-not-release
- release-check-current-commit-is-not-release:
- @$(IS_RELEASE_CURRENT_COMMIT_TEST) && { echo >&2 "ERROR: current commit is a release"; false; } || true
- .PHONY: release-check-current-commit-is-release
- release-check-current-commit-is-release:
- @$(IS_RELEASE_CURRENT_COMMIT_TEST) || { echo >&2 "ERROR: current commit is not a release"; false; }
- .PHONY: release-bumpversion
- release-bumpversion:
- @if [ ! -e "$(BUMP_VERSION_CONFIG)" ]; then \
- echo >&2 "Configuration file '$(BUMP_VERSION_CONFIG)' missing"; \
- exit 1; \
- fi
- @# bump version without committing (done after updating debian/changelog)
- @bumpversion --config-file "$(BUMP_VERSION_CONFIG)" \
- --parse "$(BUMP_VERSION_PARSE_REGEX)" \
- --current-version "$(call get_current_version)" \
- "$(VERSION_BUMP)"
- .PHONY: release-debchange
- release-debchange:
- debchange --newversion "$(call get_current_version)-1" "New upstream release"
- debchange --release ""
- .PHONY: release-git
- release-git:
- if [ -n "$(BUMP_VERSION_FILES)" ]; then git add $(BUMP_VERSION_FILES); fi
- @# add other version-related files
- if [ -n "$(BUMP_VERSION_COMMIT_FILES)" ]; then git add $(BUMP_VERSION_COMMIT_FILES); fi
- git commit -m "Bump version: $$(git show "HEAD:./$(CURRENT_VERSION_FILE)") -> $(call get_current_version)"
- git tag -a "v$(call get_current_version)" -m "Bump version: $(VERSION_BUMP)"
- .PHONY: release-npm
- release-npm:
- npm --no-git-tag-version version "$(VERSION_BUMP)"
- .PHONY: release-undo
- release-undo: release-check-current-commit-is-release
- $(IS_RELEASE_CURRENT_COMMIT_TEST)
- [ -z "$$(git status --short --untracked-files=no)" ]; # refuse to run in a non-clean working directory
- git tag -d "v$(call get_current_version)"
- git reset --hard HEAD~
- .PHONY: release-push
- release-push:
- git push --follow-tags
- .PHONY: release-tar
- release-tar: $(RELEASE_TAR_FILENAME) $(RELEASE_TAR_HASH_FILENAME)
- $(RELEASE_TAR_FILENAME):
- $(IS_RELEASE_CURRENT_COMMIT_TEST)
- git archive --prefix=$(PROJECT_NAME)-$(RELEASE)/ --format=tar HEAD \
- | "$(RELEASE_TAR_COMPRESSION_BIN)" > "$(RELEASE_TAR_FILENAME).tmp"
- mv "$(RELEASE_TAR_FILENAME).tmp" "$(RELEASE_TAR_FILENAME)"
- $(RELEASE_TAR_HASH_FILENAME): $(RELEASE_TAR_FILENAME)
- $(RELEASE_TAR_HASH_FUNC) "$<" >"$@"
- .PHONY: release-tar-sign
- release-tar-sign: $(RELEASE_TAR_SIGN_FILENAME)
- $(RELEASE_TAR_SIGN_FILENAME): $(RELEASE_TAR_FILENAME)
- gpg --armor --detach-sign --sign "$<"
|