From ae5dfc95ce630df3f6d7f50bc42f31091fa8c935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Tue, 14 Jan 2020 12:50:29 +0100 Subject: [PATCH 1/3] changelog: Remove fragment for pull request #2537 It was mistakenly left in when preparing the Change Log for release 20.0: https://github.com/oasislabs/oasis-core/pull/2540. --- .changelog/2537.trivial.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .changelog/2537.trivial.md diff --git a/.changelog/2537.trivial.md b/.changelog/2537.trivial.md deleted file mode 100644 index 2f23fdb890f..00000000000 --- a/.changelog/2537.trivial.md +++ /dev/null @@ -1 +0,0 @@ -runtime: Extract common sealing code. From 995798efd5b48247a73772f778bb94d9d226ec97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Tue, 14 Jan 2020 14:05:59 +0100 Subject: [PATCH 2/3] Makefile: Add tag-next-release target Add a bunch of helpers to common.mk to allow re-use. Refactor changelog target to use the new helpers. --- .changelog/2458.trivial.md | 1 + Makefile | 27 ++++++++++++++++++--------- common.mk | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 .changelog/2458.trivial.md diff --git a/.changelog/2458.trivial.md b/.changelog/2458.trivial.md new file mode 100644 index 00000000000..4a090794a43 --- /dev/null +++ b/.changelog/2458.trivial.md @@ -0,0 +1 @@ +Makefile: Add tag-next-release target diff --git a/Makefile b/Makefile index 58b6b2acee5..44818360fb8 100644 --- a/Makefile +++ b/Makefile @@ -97,14 +97,23 @@ clean: $(clean-targets) # Assemble Change log. changelog: - @if [[ -z "$(NEXT_VERSION)" ]]; then \ - echo "Error: Could not compute project's new version."; \ - exit 1; \ - else \ - echo "Generating changelog for version $(NEXT_VERSION)..."; \ - towncrier build --version $(NEXT_VERSION); \ - echo "Next, review the staged changes, commit them and make a pull request."; \ - fi + @$(ENSURE_NEXT_VERSION) + @$(ECHO_STDERR) "Generating Change Log for version $(NEXT_VERSION)..." + towncrier build --version $(NEXT_VERSION) + @$(ECHO_STDERR) "Next, review the staged changes, commit them and make a pull request." + +# Tag the next release. +tag-next-release: + @$(ENSURE_NEXT_VERSION) + @$(ECHO_STDERR) "Checking if we can tag version $(NEXT_VERSION) as the next release..." + @$(ENSURE_NO_CHANGELOG_FRAGMENTS) + @$(ENSURE_NEXT_VERSION_IN_CHANGELOG) + @$(ECHO_STDERR) "All checks have passed. Proceeding with tagging the origin/master HEAD with tag 'v$(NEXT_VERSION)'." + @$(CONFIRM_ACTION) + @$(ECHO_STDERR) "If this appears to be stuck, you might need to touch your security key for GPG sign operation." + @git tag --sign --message="Version $(NEXT_VERSION)" v$(NEXT_VERSION) origin/master + @git push origin v$(NEXT_VERSION) + @$(ECHO_STDERR) "$(CYAN)Tag 'v$(NEXT_VERSION)' has been successfully pushed to origin/master.$(OFF)" # Prepare release. release: @@ -128,5 +137,5 @@ docker-shell: $(fmt-targets) fmt \ $(test-unit-targets) $(test-targets) test \ $(clean-targets) clean \ - changelog release docker-shell \ + changelog tag-next-release release docker-shell \ all diff --git a/common.mk b/common.mk index 9e0790e6cb0..94e25259daa 100644 --- a/common.mk +++ b/common.mk @@ -7,6 +7,7 @@ ifdef ISATTY # Running in interactive terminal, OK to use colors! MAGENTA := \e[35;1m CYAN := \e[36;1m + RED := \e[0;31m OFF := \e[0m # Built-in echo doesn't support '-e'. @@ -15,12 +16,21 @@ else # Don't use colors if not running interactively. MAGENTA := "" CYAN := "" + RED := "" OFF := "" # OK to use built-in echo. ECHO := echo endif +# A version of echo that outputs to stderr instead of stdout. +ECHO_STDERR := $(ECHO) 1>&2 + +# Helper that asks the user to confirm the action. +define CONFIRM_ACTION = + $(ECHO_STDERR) -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ] +endef + # Try to determine Oasis Core's version from git. LATEST_TAG := $(shell git describe --tags --match 'v*' --abbrev=0 2>/dev/null) VERSION := $(subst v,,$(LATEST_TAG)) @@ -113,3 +123,31 @@ _ := $(shell printf "$(subst ",\",$(subst $(newline),\n,$(RELEASE_TEXT)))" > $(_ GORELEASER_ARGS = release --release-notes $(_RELEASE_NOTES_FILE) endif + +# Helper that ensures $(NEXT_VERSION) variable is not empty. +define ENSURE_NEXT_VERSION = + if [[ -z "$(NEXT_VERSION)" ]]; then \ + $(ECHO_STDERR) "$(RED)Error: Could not compute project's next version.$(OFF)"; \ + exit 1; \ + fi +endef + +# Helper that ensures the origin/master's HEAD doesn't contain any Change Log fragments. +define ENSURE_NO_CHANGELOG_FRAGMENTS = + CHANGELOG_FRAGMENTS=`git ls-tree -r --name-only origin/master .changelog | \ + grep --invert-match --extended-regexp '(README.md|template.md.j2)'`; \ + if [[ -n $${CHANGELOG_FRAGMENTS} ]]; then \ + $(ECHO_STDERR) "$(RED)Error: Found the following Change Log fragments on origin/master branch:"; \ + $(ECHO_STDERR) "$${CHANGELOG_FRAGMENTS}$(OFF)"; \ + exit 1; \ + fi +endef + +# Helper that ensures the origin/master's HEAD contains a Change Log section for the next release. +define ENSURE_NEXT_VERSION_IN_CHANGELOG = + if ! ( git show origin/master:CHANGELOG.md | \ + grep --quiet '^## $(NEXT_VERSION) (.*)' ); then \ + $(ECHO_STDERR) "$(RED)Error: Could not locate Change Log section for release $(NEXT_VERSION).$(OFF)"; \ + exit 1; \ + fi +endef From 63f7cb98eb95482691d89535cab0942a3e2b90b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Tue, 14 Jan 2020 18:00:14 +0100 Subject: [PATCH 3/3] Makefile: Allow specifying a custom name for git origin remote This should make it easier to test the release tooling without affecting the real releases. --- Makefile | 8 ++++---- common.mk | 18 +++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 44818360fb8..3923475bb50 100644 --- a/Makefile +++ b/Makefile @@ -108,12 +108,12 @@ tag-next-release: @$(ECHO_STDERR) "Checking if we can tag version $(NEXT_VERSION) as the next release..." @$(ENSURE_NO_CHANGELOG_FRAGMENTS) @$(ENSURE_NEXT_VERSION_IN_CHANGELOG) - @$(ECHO_STDERR) "All checks have passed. Proceeding with tagging the origin/master HEAD with tag 'v$(NEXT_VERSION)'." + @$(ECHO_STDERR) "All checks have passed. Proceeding with tagging the $(OASIS_CORE_GIT_ORIGIN_REMOTE)/master HEAD with tag 'v$(NEXT_VERSION)'." @$(CONFIRM_ACTION) @$(ECHO_STDERR) "If this appears to be stuck, you might need to touch your security key for GPG sign operation." - @git tag --sign --message="Version $(NEXT_VERSION)" v$(NEXT_VERSION) origin/master - @git push origin v$(NEXT_VERSION) - @$(ECHO_STDERR) "$(CYAN)Tag 'v$(NEXT_VERSION)' has been successfully pushed to origin/master.$(OFF)" + @git tag --sign --message="Version $(NEXT_VERSION)" v$(NEXT_VERSION) $(OASIS_CORE_GIT_ORIGIN_REMOTE)/master + @git push $(OASIS_CORE_GIT_ORIGIN_REMOTE) v$(NEXT_VERSION) + @$(ECHO_STDERR) "$(CYAN)Tag 'v$(NEXT_VERSION)' has been successfully pushed to $(OASIS_CORE_GIT_ORIGIN_REMOTE) remote.$(OFF)" # Prepare release. release: diff --git a/common.mk b/common.mk index 94e25259daa..88a30d9bb1f 100644 --- a/common.mk +++ b/common.mk @@ -31,6 +31,10 @@ define CONFIRM_ACTION = $(ECHO_STDERR) -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ] endef +# Name of git remote pointing to the canonical upstream git repository, i.e. +# git@github.com:oasislabs/oasis-core.git. +OASIS_CORE_GIT_ORIGIN_REMOTE ?= origin + # Try to determine Oasis Core's version from git. LATEST_TAG := $(shell git describe --tags --match 'v*' --abbrev=0 2>/dev/null) VERSION := $(subst v,,$(LATEST_TAG)) @@ -61,9 +65,9 @@ _PUNCH_VERSION_FILE := $(shell mktemp /tmp/oasis-core.XXXXX.py) # http://make.mad-scientist.net/deferred-simple-variable-expansion/. NEXT_VERSION ?= $(eval NEXT_VERSION := $$(shell \ set -e; \ - echo "Fetching all tags from the origin remote..." 1>&2; \ - git fetch origin --tags; \ - LATEST_TAG_ORIGIN=`git describe --tags --match 'v*' --abbrev=0 origin/master` \ + echo "Fetching all tags from the $(OASIS_CORE_GIT_ORIGIN_REMOTE) remote..." 1>&2; \ + git fetch $(OASIS_CORE_GIT_ORIGIN_REMOTE) --tags; \ + LATEST_TAG_ORIGIN=`git describe --tags --match 'v*' --abbrev=0 $(OASIS_CORE_GIT_ORIGIN_REMOTE)/master` \ python3 -c "import os; year, minor = os.environ['LATEST_TAG_ORIGIN'].lstrip('v').split('.'); \ print(f'year=\"{year}\"\nminor={minor}')" > $(_PUNCH_VERSION_FILE); \ punch --config-file .punch_config.py --version-file $(_PUNCH_VERSION_FILE) --action custom_bump --quiet; \ @@ -134,10 +138,10 @@ endef # Helper that ensures the origin/master's HEAD doesn't contain any Change Log fragments. define ENSURE_NO_CHANGELOG_FRAGMENTS = - CHANGELOG_FRAGMENTS=`git ls-tree -r --name-only origin/master .changelog | \ - grep --invert-match --extended-regexp '(README.md|template.md.j2)'`; \ + CHANGELOG_FRAGMENTS=`git ls-tree -r --name-only $(OASIS_CORE_GIT_ORIGIN_REMOTE)/master .changelog | \ + grep --invert-match --extended-regexp '(README.md|template.md.j2)'`; \ if [[ -n $${CHANGELOG_FRAGMENTS} ]]; then \ - $(ECHO_STDERR) "$(RED)Error: Found the following Change Log fragments on origin/master branch:"; \ + $(ECHO_STDERR) "$(RED)Error: Found the following Change Log fragments on $(OASIS_CORE_GIT_ORIGIN_REMOTE)/master branch:"; \ $(ECHO_STDERR) "$${CHANGELOG_FRAGMENTS}$(OFF)"; \ exit 1; \ fi @@ -145,7 +149,7 @@ endef # Helper that ensures the origin/master's HEAD contains a Change Log section for the next release. define ENSURE_NEXT_VERSION_IN_CHANGELOG = - if ! ( git show origin/master:CHANGELOG.md | \ + if ! ( git show $(OASIS_CORE_GIT_ORIGIN_REMOTE)/master:CHANGELOG.md | \ grep --quiet '^## $(NEXT_VERSION) (.*)' ); then \ $(ECHO_STDERR) "$(RED)Error: Could not locate Change Log section for release $(NEXT_VERSION).$(OFF)"; \ exit 1; \