diff --git a/.changelog/2512.trivial.md b/.changelog/2512.trivial.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/.gitignore b/.gitignore index 732a9bee43c..518b6534a80 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ target/ *.so **/generated /dist/ +/__pycache__/ # IDE. .idea/* diff --git a/.punch_config.py b/.punch_config.py new file mode 100644 index 00000000000..bcd93188738 --- /dev/null +++ b/.punch_config.py @@ -0,0 +1,28 @@ +__config_version__ = 1 + +GLOBALS = { + 'serializer': '{{year}}.{{minor}}', +} + +# NOTE: The FILES list is not allowed to be empty, so we need to pass it at +# least a single valid file. +FILES = ["README.md"] + +VERSION = [ + { + 'name': 'year', + 'type': 'date', + 'fmt': 'YY', + }, + { + 'name': 'minor', + 'type': 'integer', + }, +] +ACTIONS = { + 'custom_bump': { + 'type': 'conditional_reset', + 'field': 'minor', + 'update_fields': ['year'] + } +} diff --git a/Makefile b/Makefile index a68d520ce1c..58b6b2acee5 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,17 @@ clean-go: 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 + # Prepare release. release: @goreleaser $(GORELEASER_ARGS) @@ -117,5 +128,5 @@ docker-shell: $(fmt-targets) fmt \ $(test-unit-targets) $(test-targets) test \ $(clean-targets) clean \ - release docker-shell \ + changelog release docker-shell \ all diff --git a/common.mk b/common.mk index 2123d30a2ed..54fe20be55f 100644 --- a/common.mk +++ b/common.mk @@ -32,6 +32,26 @@ ifeq ($(and $(LATEST_TAG),$(IS_TAG)),NO) endif export VERSION +# Try to compute the next version based on the current version using the Punch +# tool. +# NOTE: This is a little messy because Punch doesn't support the following at +# the moment: +# - Passing current version as an CLI parameter. +# - Outputting the new version to stdout without making modifications to any +# files. +_PUNCH_VERSION_FILE := $(shell mktemp /tmp/oasis-core.XXXXX.py) +# NOTE: The "OUTPUT = $(eval OUTPUT := $$(shell some-comand))$(OUTPUT)" syntax +# defers simple variable expansion so that it is only computed the first time it +# is used. For more details, see: +# http://make.mad-scientist.net/deferred-simple-variable-expansion/. +NEXT_VERSION ?= $(eval NEXT_VERSION := $$(shell \ + echo "Fetching all tags from the default remote..." 1>&2 && \ + git fetch --tags && \ + python3 -c "print('year=\"{}\"\nminor={}'.format(*'$(LATEST_TAG)'.lstrip('v').split('.')))" > $(_PUNCH_VERSION_FILE) 2>/dev/null && \ + punch --config-file .punch_config.py --version-file $(_PUNCH_VERSION_FILE) --action custom_bump --quiet 2>/dev/null && \ + python3 -c "exec(open('$(_PUNCH_VERSION_FILE)').read()); print('{}.{}'.format(year, minor))" \ + ))$(NEXT_VERSION) + # Go binary to use for all Go commands. OASIS_GO ?= go