From b13dcdee2f2ed9affdf9f52700710789f5a04803 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 8 Mar 2020 16:37:43 -0400 Subject: Replace playbook with code for finalizing a release. --- tools/finalize.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tools/finalize.py (limited to 'tools/finalize.py') 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() -- cgit v1.2.1 From 03b92ca154951f16851e75b01b78b9127dad742f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 6 Apr 2020 16:33:15 -0400 Subject: Protect against situation where the Git user e-mail is not configured. Ref #2057. --- tools/finalize.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tools/finalize.py') diff --git a/tools/finalize.py b/tools/finalize.py index 3b66341a..5f284568 100644 --- a/tools/finalize.py +++ b/tools/finalize.py @@ -53,7 +53,15 @@ def bump_version(): subprocess.check_call(cmd) +def ensure_config(): + """ + Double-check that Git has an e-mail configured. + """ + subprocess.check_output(['git', 'config', 'user.email']) + + if __name__ == '__main__': print("Cutting release at", get_version()) + ensure_config() update_changelog() bump_version() -- cgit v1.2.1 From c79400a2839527d0749798637d182b1cb3d84a01 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 13 May 2020 14:24:42 -0400 Subject: Ensure that the changelog.d doesn't contain files that won't match. --- tools/finalize.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tools/finalize.py') diff --git a/tools/finalize.py b/tools/finalize.py index 5f284568..98b06c07 100644 --- a/tools/finalize.py +++ b/tools/finalize.py @@ -60,8 +60,22 @@ def ensure_config(): subprocess.check_output(['git', 'config', 'user.email']) +def check_changes(): + """ + Verify that all of the files in changelog.d have the appropriate + names. + """ + allowed = 'deprecation', 'breaking', 'change', 'doc', 'misc' + assert all( + any(key in file.name for key in allowed) + for file in pathlib.Path('changelog.d').iterdir() + if file.name != '.gitignore' + ) + + if __name__ == '__main__': print("Cutting release at", get_version()) ensure_config() + check_changes() update_changelog() bump_version() -- cgit v1.2.1 From f0878e963c3a1086570712d072e967e5c8b57e6a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 14 Oct 2020 20:09:11 -0400 Subject: Exempt README as well. Ref #2395. --- tools/finalize.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools/finalize.py') diff --git a/tools/finalize.py b/tools/finalize.py index 98b06c07..35294281 100644 --- a/tools/finalize.py +++ b/tools/finalize.py @@ -66,10 +66,11 @@ def check_changes(): names. """ allowed = 'deprecation', 'breaking', 'change', 'doc', 'misc' + except_ = 'README.rst', '.gitignore' assert all( any(key in file.name for key in allowed) for file in pathlib.Path('changelog.d').iterdir() - if file.name != '.gitignore' + if file.name not in except_ ) -- cgit v1.2.1 From 4c46ae7979e90c52a2eab00166661c60fb6e560f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 9 May 2021 12:09:36 -0400 Subject: Add workaround for #2666. --- tools/finalize.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tools/finalize.py') diff --git a/tools/finalize.py b/tools/finalize.py index 35294281..516a2fb5 100644 --- a/tools/finalize.py +++ b/tools/finalize.py @@ -46,6 +46,18 @@ def update_changelog(): '--yes', ] subprocess.check_call(cmd) + _repair_changelog() + + +def _repair_changelog(): + """ + Workaround for #2666 + """ + changelog_fn = pathlib.Path('CHANGES.rst') + changelog = changelog_fn.read_text() + fixed = re.sub(r'^(v[0-9.]+)v[0-9.]+$', r'\1', changelog, flags=re.M) + changelog_fn.write_text(fixed) + subprocess.check_output(['git', 'add', changelog_fn]) def bump_version(): -- cgit v1.2.1