11# mypy: disallow-untyped-defs
22"""
3- Script used to publish GitHub release notes extracted from CHANGELOG.rst.
3+ Script used to generate a Markdown file containing only the changelog entries of a specific pytest release, which
4+ is then published as a GitHub Release during deploy (see workflows/deploy.yml).
45
5- This script is meant to be executed after a successful deployment in GitHub actions.
6-
7- Uses the following environment variables:
8-
9- * GIT_TAG: the name of the tag of the current commit.
10- * GH_RELEASE_NOTES_TOKEN: a personal access token with 'repo' permissions.
11-
12- Create one at:
13-
14- https://github.com/settings/tokens
15-
16- This token should be set in a secret in the repository, which is exposed as an
17- environment variable in the main.yml workflow file.
18-
19- The script also requires ``pandoc`` to be previously installed in the system.
6+ The script requires ``pandoc`` to be previously installed in the system -- we need to convert from RST (the format of
7+ our CHANGELOG) into Markdown (which is required by GitHub Releases).
208
219Requires Python3.6+.
2210"""
2816import pypandoc
2917
3018
31- def parse_changelog ( tag_name : str ) -> str :
19+ def extract_changelog_entries_for ( version : str ) -> str :
3220 p = Path (__file__ ).parent .parent / "doc/en/changelog.rst"
3321 changelog_lines = p .read_text (encoding = "UTF-8" ).splitlines ()
3422
@@ -38,10 +26,10 @@ def parse_changelog(tag_name: str) -> str:
3826 for line in changelog_lines :
3927 m = title_regex .match (line )
4028 if m :
41- # found the version we want: start to consume lines until we find the next version title
42- if m .group (1 ) == tag_name :
29+ # Found the version we want: start to consume lines until we find the next version title.
30+ if m .group (1 ) == version :
4331 consuming_version = True
44- # found a new version title while parsing the version we want: break out
32+ # Found a new version title while parsing the version we want: break out.
4533 elif consuming_version :
4634 break
4735 if consuming_version :
@@ -65,7 +53,7 @@ def main(argv: Sequence[str]) -> int:
6553
6654 version , filename = argv [1 :3 ]
6755 print (f"Generating GitHub release notes for version { version } " )
68- rst_body = parse_changelog (version )
56+ rst_body = extract_changelog_entries_for (version )
6957 md_body = convert_rst_to_md (rst_body )
7058 Path (filename ).write_text (md_body , encoding = "UTF-8" )
7159 print ()
0 commit comments