Skip to content

[8.0.x] Update docstring of scripts/generate-gh-release-notes.py #11768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions scripts/generate-gh-release-notes.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# mypy: disallow-untyped-defs
"""
Script used to publish GitHub release notes extracted from CHANGELOG.rst.
Script used to generate a Markdown file containing only the changelog entries of a specific pytest release, which
is then published as a GitHub Release during deploy (see workflows/deploy.yml).

This script is meant to be executed after a successful deployment in GitHub actions.

Uses the following environment variables:

* GIT_TAG: the name of the tag of the current commit.
* GH_RELEASE_NOTES_TOKEN: a personal access token with 'repo' permissions.

Create one at:

https://github.com/settings/tokens

This token should be set in a secret in the repository, which is exposed as an
environment variable in the main.yml workflow file.

The script also requires ``pandoc`` to be previously installed in the system.
The script requires ``pandoc`` to be previously installed in the system -- we need to convert from RST (the format of
our CHANGELOG) into Markdown (which is required by GitHub Releases).

Requires Python3.6+.
"""
Expand All @@ -28,7 +16,7 @@
import pypandoc


def parse_changelog(tag_name: str) -> str:
def extract_changelog_entries_for(version: str) -> str:
p = Path(__file__).parent.parent / "doc/en/changelog.rst"
changelog_lines = p.read_text(encoding="UTF-8").splitlines()

Expand All @@ -38,10 +26,10 @@ def parse_changelog(tag_name: str) -> str:
for line in changelog_lines:
m = title_regex.match(line)
if m:
# found the version we want: start to consume lines until we find the next version title
if m.group(1) == tag_name:
# Found the version we want: start to consume lines until we find the next version title.
if m.group(1) == version:
consuming_version = True
# found a new version title while parsing the version we want: break out
# Found a new version title while parsing the version we want: break out.
elif consuming_version:
break
if consuming_version:
Expand All @@ -65,7 +53,7 @@ def main(argv: Sequence[str]) -> int:

version, filename = argv[1:3]
print(f"Generating GitHub release notes for version {version}")
rst_body = parse_changelog(version)
rst_body = extract_changelog_entries_for(version)
md_body = convert_rst_to_md(rst_body)
Path(filename).write_text(md_body, encoding="UTF-8")
print()
Expand Down