diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-03-08 16:37:43 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-03-08 16:37:43 -0400 |
commit | b13dcdee2f2ed9affdf9f52700710789f5a04803 (patch) | |
tree | 6957966a6748f3add244f9efae237e8bbf94f952 /tools/finalize.py | |
parent | 50f3575da42ce5b7c013c28ff623ce16c231455d (diff) | |
download | external_python_setuptools-b13dcdee2f2ed9affdf9f52700710789f5a04803.tar.gz external_python_setuptools-b13dcdee2f2ed9affdf9f52700710789f5a04803.tar.bz2 external_python_setuptools-b13dcdee2f2ed9affdf9f52700710789f5a04803.zip |
Replace playbook with code for finalizing a release.
Diffstat (limited to 'tools/finalize.py')
-rw-r--r-- | tools/finalize.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tools/finalize.py b/tools/finalize.py new file mode 100644 index 00000000..3b66341a --- /dev/null +++ b/tools/finalize.py @@ -0,0 +1,59 @@ +""" +Finalize the repo for a release. Invokes towncrier and bumpversion. +""" + +__requires__ = ['bump2version', 'towncrier'] + + +import subprocess +import pathlib +import re +import sys + + +def release_kind(): + """ + Determine which release to make based on the files in the + changelog. + """ + # use min here as 'major' < 'minor' < 'patch' + return min( + 'major' if 'breaking' in file.name else + 'minor' if 'change' in file.name else + 'patch' + for file in pathlib.Path('changelog.d').iterdir() + ) + + +bump_version_command = [ + sys.executable, + '-m', 'bumpversion', + release_kind(), +] + + +def get_version(): + cmd = bump_version_command + ['--dry-run', '--verbose'] + out = subprocess.check_output(cmd, text=True) + return re.search('^new_version=(.*)', out, re.MULTILINE).group(1) + + +def update_changelog(): + cmd = [ + sys.executable, '-m', + 'towncrier', + '--version', get_version(), + '--yes', + ] + subprocess.check_call(cmd) + + +def bump_version(): + cmd = bump_version_command + ['--allow-dirty'] + subprocess.check_call(cmd) + + +if __name__ == '__main__': + print("Cutting release at", get_version()) + update_changelog() + bump_version() |