Skip to content

Commit

Permalink
Make: Miscellaneous smaller improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanez committed Nov 6, 2020
1 parent 2ae6fbd commit 5124dc7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 40 deletions.
28 changes: 13 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env gmake

include common.mk

# List of runtimes to build.
Expand Down Expand Up @@ -73,9 +71,9 @@ lint-go:
# NOTE: gitlint internally uses git rev-list, where A..B is asymmetric difference, which is kind of the opposite of
# how git diff interprets A..B vs A...B.
lint-git: fetch-git
@COMMIT_SHA=`git rev-parse $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)` && \
echo "Running gitlint for commits from $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) ($${COMMIT_SHA:0:7})..."; \
gitlint --commits $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)..HEAD
@COMMIT_SHA=`git rev-parse $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)` && \
echo "Running gitlint for commits from $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) ($${COMMIT_SHA:0:7})..."; \
gitlint --commits $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)..HEAD

lint-md:
@npx markdownlint-cli '**/*.md' --ignore .changelog/
Expand Down Expand Up @@ -132,8 +130,8 @@ clean: $(clean-targets)
# Fetch all the latest changes (including tags) from the canonical upstream git
# repository.
fetch-git:
@$(ECHO) "Fetching the latest changes (including tags) from $(OASIS_CORE_GIT_ORIGIN_REMOTE) remote..."
@git fetch $(OASIS_CORE_GIT_ORIGIN_REMOTE) --tags
@$(ECHO) "Fetching the latest changes (including tags) from $(GIT_ORIGIN_REMOTE) remote..."
@git fetch $(GIT_ORIGIN_REMOTE) --tags

# Private target for bumping project's version using the Punch tool.
# NOTE: It should not be invoked directly.
Expand Down Expand Up @@ -164,26 +162,26 @@ release-tag: fetch-git
@$(ENSURE_RELEASE_TAG_DOES_NOT_EXIST)
@$(ENSURE_NO_CHANGELOG_FRAGMENTS)
@$(ENSURE_NEXT_RELEASE_IN_CHANGELOG)
@$(ECHO) "All checks have passed. Proceeding with tagging the $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)'s HEAD with tags:\n- $(RELEASE_TAG)\n- $(RELEASE_TAG_GO)"
@$(ECHO) "All checks have passed. Proceeding with tagging the $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)'s HEAD with tags:\n- $(RELEASE_TAG)\n- $(RELEASE_TAG_GO)"
@$(CONFIRM_ACTION)
@$(ECHO) "If this appears to be stuck, you might need to touch your security key for GPG sign operation."
@git tag --sign --message="Version $(PUNCH_VERSION)" $(RELEASE_TAG) $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)
@git tag --sign --message="Version $(PUNCH_VERSION)" $(RELEASE_TAG) $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)
@$(ECHO) "If this appears to be stuck, you might need to touch your security key for GPG sign operation."
@git tag --sign --message="Version $(PUNCH_VERSION)" $(RELEASE_TAG_GO) $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)
@git push $(OASIS_CORE_GIT_ORIGIN_REMOTE) $(RELEASE_TAG) $(RELEASE_TAG_GO)
@$(ECHO) "$(CYAN)*** The following tags have been successfully pushed to $(OASIS_CORE_GIT_ORIGIN_REMOTE) remote:\n- $(RELEASE_TAG)\n- $(RELEASE_TAG_GO)$(OFF)"
@git tag --sign --message="Version $(PUNCH_VERSION)" $(RELEASE_TAG_GO) $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH)
@git push $(GIT_ORIGIN_REMOTE) $(RELEASE_TAG) $(RELEASE_TAG_GO)
@$(ECHO) "$(CYAN)*** The following tags have been successfully pushed to $(GIT_ORIGIN_REMOTE) remote:\n- $(RELEASE_TAG)\n- $(RELEASE_TAG_GO)$(OFF)"

# Create and push a stable branch for the current release.
release-stable-branch: fetch-git
@$(ECHO) "Checking if we can create a stable release branch for version $(PUNCH_VERSION)...$(OFF)"
@$(ENSURE_VALID_STABLE_BRANCH)
@$(ENSURE_RELEASE_TAG_EXISTS)
@$(ENSURE_STABLE_BRANCH_DOES_NOT_EXIST)
@$(ECHO) "All checks have passed. Proceeding with creating the '$(STABLE_BRANCH)' branch on $(OASIS_CORE_GIT_ORIGIN_REMOTE) remote."
@$(ECHO) "All checks have passed. Proceeding with creating the '$(STABLE_BRANCH)' branch on $(GIT_ORIGIN_REMOTE) remote."
@$(CONFIRM_ACTION)
@git branch $(STABLE_BRANCH) $(RELEASE_TAG)
@git push $(OASIS_CORE_GIT_ORIGIN_REMOTE) $(STABLE_BRANCH)
@$(ECHO) "$(CYAN)*** Branch '$(STABLE_BRANCH)' has been sucessfully pushed to $(OASIS_CORE_GIT_ORIGIN_REMOTE) remote.$(OFF)"
@git push $(GIT_ORIGIN_REMOTE) $(STABLE_BRANCH)
@$(ECHO) "$(CYAN)*** Branch '$(STABLE_BRANCH)' has been sucessfully pushed to $(GIT_ORIGIN_REMOTE) remote.$(OFF)"

# Build and publish the next release.
release-build:
Expand Down
51 changes: 28 additions & 23 deletions common.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
SHELL := /bin/bash
# Use Bash shell.
# NOTE: You can control which Bash version is used by setting the PATH
# appropriately.
SHELL := bash

# Path to the directory of this Makefile.
# NOTE: Prepend all relative paths in this Makefile with this variable to ensure
Expand All @@ -19,8 +22,7 @@ ifdef ISATTY
CYAN := \e[36;1m
RED := \e[0;31m
OFF := \e[0m
# Use external echo command since the built-in echo doesn't support '-e'.
ECHO_CMD := /bin/echo -e
ECHO_CMD := echo -e
else
MAGENTA := ""
CYAN := ""
Expand All @@ -44,25 +46,25 @@ endef

# Name of git remote pointing to the canonical upstream git repository, i.e.
# [email protected]:oasisprotocol/oasis-core.git.
OASIS_CORE_GIT_ORIGIN_REMOTE ?= origin
GIT_ORIGIN_REMOTE ?= origin

# Name of the branch where to tag the next release.
RELEASE_BRANCH ?= master

# Determine project's version from git.
# NOTE: This computes the project's version from the latest version tag
# reachable from the given $(RELEASE_BRANCH) and does not search for version
# tags across the whole $(OASIS_CORE_GIT_ORIGIN_REMOTE) repository.
# tags across the whole $(GIT_ORIGIN_REMOTE) repository.
GIT_VERSION := $(subst v,,$(shell \
git describe --tags --match 'v*' --abbrev=0 2>/dev/null $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) || \
git describe --tags --match 'v*' --abbrev=0 2>/dev/null $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) || \
echo undefined \
))

# Determine project's git branch.
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)

PUNCH_CONFIG_FILE := $(SELF_DIR)/.punch_config.py
PUNCH_VERSION_FILE := $(SELF_DIR)/.punch_version.py
PUNCH_CONFIG_FILE := $(abspath $(SELF_DIR)/.punch_config.py)
PUNCH_VERSION_FILE := $(abspath $(SELF_DIR)/.punch_version.py)
# Obtain project's version as tracked by the Punch tool.
# NOTE: The Punch tool doesn't have the ability fo print project's version to
# stdout yet.
Expand All @@ -71,15 +73,15 @@ PUNCH_VERSION := $(shell \
python3 -c "exec(open('$(PUNCH_VERSION_FILE)').read()); \
version = f'{year}.{minor}.{micro}' if micro > 0 else f'{year}.{minor}'; \
print(version)" \
)
)

# Determine project's version.
# If the current git commit is exactly a tag and it equals the Punch version,
# then the project's version is that.
# Else, the project version is the Punch version appended with git commit and
# dirty state info.
GIT_COMMIT_EXACT_TAG := $(shell \
git describe --tags --match 'v*' --exact-match &>/dev/null $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) && echo YES || echo NO \
git describe --tags --match 'v*' --exact-match &>/dev/null $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) && echo YES || echo NO \
)
VERSION := $(or \
$(and $(call eq,$(GIT_COMMIT_EXACT_TAG),YES), $(call eq,$(GIT_VERSION),$(PUNCH_VERSION))), \
Expand Down Expand Up @@ -112,7 +114,7 @@ endef
# version as tracked by the Punch tool.
define ENSURE_GIT_VERSION_EQUALS_PUNCH_VERSION =
if [[ "$(GIT_VERSION)" != "$(PUNCH_VERSION)" ]]; then \
$(ECHO) "$(RED)Error: Project's version for $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) \
$(ECHO) "$(RED)Error: Project's version for $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) \
determined from git ($(GIT_VERSION)) doesn't equal project's version in \
$(PUNCH_VERSION_FILE) ($(PUNCH_VERSION)).$(OFF)"; \
exit 1; \
Expand Down Expand Up @@ -188,12 +190,12 @@ endef
# Helper that ensures the origin's release branch's HEAD doesn't contain any
# Change Log fragments.
define ENSURE_NO_CHANGELOG_FRAGMENTS =
if ! CHANGELOG_FILES=`git ls-tree -r --name-only $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) .changelog`; then \
$(ECHO) "$(RED)Error: Could not obtain Change Log fragments for $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) branch.$(OFF)"; \
if ! CHANGELOG_FILES=`git ls-tree -r --name-only $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) .changelog`; then \
$(ECHO) "$(RED)Error: Could not obtain Change Log fragments for $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) branch.$(OFF)"; \
exit 1; \
fi; \
if CHANGELOG_FRAGMENTS=`echo "$$CHANGELOG_FILES" | grep --invert-match --extended-regexp '(README.md|template.md.j2|.markdownlint.yml)'`; then \
$(ECHO) "$(RED)Error: Found the following Change Log fragments on $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) branch:"; \
$(ECHO) "$(RED)Error: Found the following Change Log fragments on $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) branch:"; \
$(ECHO) "$${CHANGELOG_FRAGMENTS}$(OFF)"; \
exit 1; \
fi
Expand All @@ -202,9 +204,9 @@ endef
# Helper that ensures the origin's release branch's HEAD contains a Change Log
# section for the next release.
define ENSURE_NEXT_RELEASE_IN_CHANGELOG =
if ! ( git show $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH):CHANGELOG.md | \
if ! ( git show $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH):CHANGELOG.md | \
grep --quiet '^## $(PUNCH_VERSION) (.*)' ); then \
$(ECHO) "$(RED)Error: Could not locate Change Log section for release $(PUNCH_VERSION) on $(OASIS_CORE_GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) branch.$(OFF)"; \
$(ECHO) "$(RED)Error: Could not locate Change Log section for release $(PUNCH_VERSION) on $(GIT_ORIGIN_REMOTE)/$(RELEASE_BRANCH) branch.$(OFF)"; \
exit 1; \
fi
endef
Expand All @@ -221,17 +223,17 @@ RELEASE_TAG_GO := $(shell \
# Helper that ensures the new release's tag doesn't already exist on the origin
# remote.
define ENSURE_RELEASE_TAG_EXISTS =
if ! git ls-remote --exit-code --tags $(OASIS_CORE_GIT_ORIGIN_REMOTE) $(RELEASE_TAG) 1>/dev/null; then \
$(ECHO) "$(RED)Error: Tag '$(RELEASE_TAG)' doesn't exist on $(OASIS_CORE_GIT_ORIGIN_REMOTE) remote.$(OFF)"; \
if ! git ls-remote --exit-code --tags $(GIT_ORIGIN_REMOTE) $(RELEASE_TAG) 1>/dev/null; then \
$(ECHO) "$(RED)Error: Tag '$(RELEASE_TAG)' doesn't exist on $(GIT_ORIGIN_REMOTE) remote.$(OFF)"; \
exit 1; \
fi
endef

# Helper that ensures the new release's tag doesn't already exist on the origin
# remote.
define ENSURE_RELEASE_TAG_DOES_NOT_EXIST =
if git ls-remote --exit-code --tags $(OASIS_CORE_GIT_ORIGIN_REMOTE) $(RELEASE_TAG) 1>/dev/null; then \
$(ECHO) "$(RED)Error: Tag '$(RELEASE_TAG)' already exists on $(OASIS_CORE_GIT_ORIGIN_REMOTE) remote.$(OFF)"; \
if git ls-remote --exit-code --tags $(GIT_ORIGIN_REMOTE) $(RELEASE_TAG) 1>/dev/null; then \
$(ECHO) "$(RED)Error: Tag '$(RELEASE_TAG)' already exists on $(GIT_ORIGIN_REMOTE) remote.$(OFF)"; \
exit 1; \
fi; \
if git show-ref --quiet --tags $(RELEASE_TAG); then \
Expand All @@ -241,7 +243,10 @@ define ENSURE_RELEASE_TAG_DOES_NOT_EXIST =
endef

# Name of the stable release branch (if the current version is appropriate).
STABLE_BRANCH := $(shell python3 -c "exec(open('$(PUNCH_VERSION_FILE)').read()); print(f'stable/{year}.{minor}.x') if micro == 0 else print('undefined')")
STABLE_BRANCH := $(shell \
python3 -c "exec(open('$(PUNCH_VERSION_FILE)').read()); \
print(f'stable/{year}.{minor}.x') if micro == 0 else print('undefined')" \
)

# Helper that ensures the stable branch name is valid.
define ENSURE_VALID_STABLE_BRANCH =
Expand All @@ -254,8 +259,8 @@ endef
# Helper that ensures the new stable branch doesn't already exist on the origin
# remote.
define ENSURE_STABLE_BRANCH_DOES_NOT_EXIST =
if git ls-remote --exit-code --heads $(OASIS_CORE_GIT_ORIGIN_REMOTE) $(STABLE_BRANCH) 1>/dev/null; then \
$(ECHO) "$(RED)Error: Branch '$(STABLE_BRANCH)' already exists on $(OASIS_CORE_GIT_ORIGIN_REMOTE) remote.$(OFF)"; \
if git ls-remote --exit-code --heads $(GIT_ORIGIN_REMOTE) $(STABLE_BRANCH) 1>/dev/null; then \
$(ECHO) "$(RED)Error: Branch '$(STABLE_BRANCH)' already exists on $(GIT_ORIGIN_REMOTE) remote.$(OFF)"; \
exit 1; \
fi; \
if git show-ref --quiet --heads $(STABLE_BRANCH); then \
Expand Down
4 changes: 2 additions & 2 deletions docs/release-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ is being made to know which part of the project's version to bump.
To customize the release process, one can set the following environment
variables:

- `OASIS_CORE_GIT_ORIGIN_REMOTE` (default: `origin`): Name of the git remote
pointing to the canonical upstream git repository.
- `GIT_ORIGIN_REMOTE` (default: `origin`): Name of the git remote pointing to
the canonical upstream git repository.
- `RELEASE_BRANCH` (default: `master`): Name of the branch where to tag the next
release.

Expand Down

0 comments on commit 5124dc7

Please sign in to comment.