From 8bb2c317fde08a6ea04511b3bae1d6b9636fb607 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Tue, 24 Nov 2020 10:54:08 -0700 Subject: [PATCH] Rewrite changelog helper to Python and use markdown for changelog (#11224) Some changes: * You now specify the `--prior` and `--new` versions as CLI args, e.g. `--prior 2.1.0 --new 2.2.0.dev0`. Before, it asked for the prior Git tag as an `input()` once the script was running. * We use markdown, which is simpler to work with. * We don't need to worry about compat with the v1 site. * It says which file to modify. * The version header is generated. * We represent the date as `(Nov 20, 2020)`, rather than `(11/20/20)`. This avoids any confusion for non-US users. * We no longer include related PRs and issues. It was a bit confusing what those meant, and the user should open the original PR to get more info anyways. [ci skip-rust] [ci skip-build-wheels] --- build-support/bin/BUILD | 7 +- build-support/bin/changelog.py | 109 ++++++++++++++++ build-support/bin/release-changelog-helper.sh | 122 ------------------ 3 files changed, 114 insertions(+), 124 deletions(-) create mode 100755 build-support/bin/changelog.py delete mode 100755 build-support/bin/release-changelog-helper.sh diff --git a/build-support/bin/BUILD b/build-support/bin/BUILD index d436757e548..f0cdc791306 100644 --- a/build-support/bin/BUILD +++ b/build-support/bin/BUILD @@ -17,6 +17,11 @@ pex_binary( sources = ['bootstrap_and_deploy_ci_pants_pex.py'], ) +pex_binary( + name="changelog", + sources=["changelog.py"], +) + pex_binary( name = 'check_banned_imports', sources = ['check_banned_imports.py'], @@ -80,5 +85,3 @@ pex_binary( name = "packages", sources = ["packages.py"], ) - -python_tests() \ No newline at end of file diff --git a/build-support/bin/changelog.py b/build-support/bin/changelog.py new file mode 100755 index 00000000000..c0517bd9aba --- /dev/null +++ b/build-support/bin/changelog.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). +# Licensed under the Apache License, Version 2.0 (see LICENSE). + +import argparse +import datetime +import re +import subprocess +from textwrap import dedent +from typing import List + + +def create_parser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser(description="Prepare the changelog for a release.") + parser.add_argument( + "--prior", + required=True, + type=str, + help="The version of the prior release, e.g. `2.0.0.dev0` or `2.0.0rc1`.", + ) + parser.add_argument( + "--new", + required=True, + type=str, + help="The version for the new release, e.g. `2.0.0.dev0` or `2.0.0rc1`.", + ) + return parser + + +def relevant_shas(prior: str) -> List[str]: + prior_tag = f"release_{prior}" + return ( + subprocess.run( + ["git", "log", "--format=format:%H", "HEAD", f"^{prior_tag}"], + check=True, + stdout=subprocess.PIPE, + ) + .stdout.decode() + .splitlines() + ) + + +def prepare_sha(sha: str) -> str: + subject = ( + subprocess.run( + ["git", "log", "-1", "--format=format:%s", sha], + check=True, + stdout=subprocess.PIPE, + ) + .stdout.decode() + .strip() + ) + pr_num_match = re.search(r"\(#(\d{4,5})\)\s*$", subject) + if not pr_num_match: + return f"* {subject}" + pr_num = pr_num_match.groups()[0] + pr_url = f"https://github.com/pantsbuild/pants/pull/{pr_num}" + subject_with_url = subject.replace(f"(#{pr_num})", f"([#{pr_num}]({pr_url}))") + return f"* {subject_with_url.capitalize()}" + + +def instructions(new_version: str) -> str: + date = datetime.date.today().strftime("%b %d, %Y") + version_components = new_version.split(".", maxsplit=4) + major, minor = version_components[0], version_components[1] + return dedent( + f"""\ + Copy the below headers into `src/python/notes/{major}.{minor}.x.md`. Then, put each commit + into the relevant category. You can tweak descriptions to be more descriptive or to fix + typos, and you can reorder based on relative importance to end users. Delete any unused + headers. + + --------------------------------------------------------------------- + + # {new_version} ({date}) + + ## New Features + + + ## User API Changes + + + ## Plugin API Changes + + + ## Bug fixes + + + ## Documentation + + + ## Internal only (Copy into the PR description, rather than the release notes) + + + -------------------------------------------------------------------- + + """ + ) + + +def main() -> None: + args = create_parser().parse_args() + print(instructions(args.new)) + entries = [prepare_sha(sha) for sha in relevant_shas(args.prior)] + print("\n\n".join(entries)) + + +if __name__ == "__main__": + main() diff --git a/build-support/bin/release-changelog-helper.sh b/build-support/bin/release-changelog-helper.sh deleted file mode 100755 index a73a9d6d9f8..00000000000 --- a/build-support/bin/release-changelog-helper.sh +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env bash - -function help() { - echo "Usage: $0 [-h|]" - echo - echo " -h display this help" - echo " With no arguments, prompts for the last release sha" - echo - echo "Attempts to generate a mostly complete changelog .rst section" - echo "given the last release sha. Each commit since that sha will" - echo "have an RST compatible bullet generated with commit summary" - echo "and ISSUE/RB links if present in the commit message. A" - echo "header not intended for the changelog is included to provide" - echo "information about the commit in case more investigation is" - echo "needed." - if (( $# > 0 )) - then - echo - echo "$@" - exit 1 - else - exit - fi -} - -if (( $# > 1 )) -then - help "Too many arguments." -elif (( $# == 0 )) -then - read -rp "What git commit hash or tag was the last release made from?: " LAST_RELEASE_IDENTIFIER -elif [[ "$1" == "-h" ]] -then - help -else - LAST_RELEASE_IDENTIFIER="$1" -fi - -echo -echo "Headers. Delete any that are unused." -echo "We do not include internal-only changes. However, in the release prep PR, it's helpful to put" \ - "these internal-only changes in a comment so that other reviewers can check if any should be added" \ - "back to the changelog." -echo "----------------------------------------------------------------------------------------------------" -cat <\`_" - fi - done - - for url in "${urls[@]}" - do - if echo "${url}" | grep github.com | grep -q /pull/ - then - issue=${url##*/} - echo " \`PR #${issue} <${url}>\`_" - fi - done - - echo -done