Skip to content

Commit

Permalink
Merge pull request #2532 from oasislabs/tjanez/auto-version
Browse files Browse the repository at this point in the history
More release automation
  • Loading branch information
tjanez authored Jan 9, 2020
2 parents 397353d + 0cb48ed commit 05adb32
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
Empty file added .changelog/2512.trivial.md
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target/
*.so
**/generated
/dist/
/__pycache__/

# IDE.
.idea/*
Expand Down
28 changes: 28 additions & 0 deletions .punch_config.py
Original file line number Diff line number Diff line change
@@ -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']
}
}
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
20 changes: 20 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 05adb32

Please sign in to comment.