Skip to content

Commit

Permalink
Rewrite changelog helper to Python and use markdown for changelog (pa…
Browse files Browse the repository at this point in the history
…ntsbuild#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]
  • Loading branch information
Eric-Arellano authored Nov 24, 2020
1 parent 82fc6ca commit 8bb2c31
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 124 deletions.
7 changes: 5 additions & 2 deletions build-support/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -80,5 +85,3 @@ pex_binary(
name = "packages",
sources = ["packages.py"],
)

python_tests()
109 changes: 109 additions & 0 deletions build-support/bin/changelog.py
Original file line number Diff line number Diff line change
@@ -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()
122 changes: 0 additions & 122 deletions build-support/bin/release-changelog-helper.sh

This file was deleted.

0 comments on commit 8bb2c31

Please sign in to comment.