Skip to content

Commit

Permalink
Use Punch utility to compute the next version from the latest git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanez committed Jan 9, 2020
1 parent 397353d commit 178d69e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
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']
}
}
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 178d69e

Please sign in to comment.