Script to help with marking and pushing a new release in git.
python release.py -h
usage: Mark git release [-h] --release RELEASE --config CONFIG
optional arguments:
-h, --help show this help message and exit
--release RELEASE, -r RELEASE
Release version string
--config CONFIG, -c CONFIG
Config file
Script does the following:
- Get last version from git tags.
- Get current version from first
version_strings
entry inCONFIG
. - Compare last and current version to
RELEASE
to make sure order is correct. - Change
version_strings
paths/patterns to use newRELEASE
. - Commit changes with message about new release version and tag the commit with the version number.
- Run
make clean
andmake
. - Push the new release commit and tag.
- If
github
is configured inCONFIG
, convert tag to a GitHub release and upload assets to it. - Bump
version_strings
again to an alpha version one micro version ahead ofRELEASE
and make a new commit with this version string change.
Config file is a yaml file with a version_strings
block containing a list of mappings containing path
and pattern
entries. path
is a file path relative to the git root directory. pattern
is a Python regular expression with a group named release
(i.e. something like (?P<release>\d+\.\d+\.\d+[ab]\d+)
. That file will be searched line by line for that pattern and when found the release
will be replaced with the new release version string.
The first entry in version_strings
list is used to determine the current version when sanity checking. If RELEASE
is lower than the current version, an exception is raised. Also, if the current version is lower than the latest tagged release, an exception is raised. This check is there to prevent accidentally releasing from an old branch.
The config can optionally contain a git_release
mapping with remote
and branch
entries. When this entry is present, the release commit is pushed to this branch on this remote (in additon to the push the default upstream branch done with a simple git push
). The main purpose of this git_release
entry to maintain a branch whose HEAD is always pointing to the most recent stable release.
The config can also contain a github
mapping with user
, repo
, token
and assets
entries. assets
is a list mappings with path
and type
entries. These file paths relative to the git root will be attached to a GitHub release for RELEASE
. The type
is the MIME type as required by GitHub. user
and repo
are the user and repo to create the release for on GitHub. token
is a text file containing the authorization token required to use the GitHub API for that repo.