Skip to content
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

DEV: Ensure the REL commit message is consistently created #2126

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ tests/pdf_cache/
docs/meta/CHANGELOG.md
docs/meta/CONTRIBUTORS.md
extracted-images/

RELEASE_COMMIT_MSG.md
18 changes: 16 additions & 2 deletions make_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def main(changelog_path: str) -> None:
if changes == "":
print("No changes")
return
print(changes)

new_version = version_bump(git_tag)
today = datetime.now(tz=timezone.utc)
Expand All @@ -37,6 +36,7 @@ def main(changelog_path: str) -> None:
trailer = f"\n[Full Changelog]({url})\n\n"
new_entry = header + changes + trailer
print(new_entry)
write_commit_msg_file(new_version, changes + trailer)

# Make the script idempotent by checking if the new entry is already in the changelog
if new_entry in changelog:
Expand All @@ -47,9 +47,23 @@ def main(changelog_path: str) -> None:
write_changelog(new_changelog, changelog_path)


def write_commit_msg_file(new_version: str, commit_changes: str) -> None:
"""
Write a file that can be used as a commit message.

Like this:

git commit -eF RELEASE_COMMIT_MSG.md && git push
"""
with open("RELEASE_COMMIT_MSG.md", "w") as fp:
fp.write(f"REL: {new_version}\n\n")
fp.write("## What's new\n")
fp.write(commit_changes)


def strip_header(md: str) -> str:
"""Remove the 'CHANGELOG' header."""
return md.lstrip("# CHANGELOG").strip() # noqa
return md.lstrip("# CHANGELOG").lstrip() # noqa


def version_bump(git_tag: str) -> str:
Expand Down