-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
I use a GitHub Actions script to update my changelog with the latest PRs merged between version tags. My script calls this package to release the new version:
def update_changelog(version, fragment_path, changelog_path="CHANGELOG.md"):
"""
Reads existing changelog, merges unreleased notes with the new fragment,
and finalizes the release.
TODO: keepachangelog.release modifies the new version in place (top of file) while keepachangelog.from_dict writes it to the end (in the order of data.values()). Decide the direction of new versions and reconcile branches to conform to this.
"""
release_date = datetime.date.today().strftime("%Y-%m-%d")
changelog_dict = _read_and_parse(changelog_path, show_unreleased=True)
fragment_dict = _read_and_parse(fragment_path)
if not fragment_dict:
newv = keepachangelog.release(changelog_path, version)
if newv:
print(f"Bumped unreleased version to {newv} in {changelog_path}. View compare view to see changes.")
else:
print(f"Failed to release version {version} in {changelog_path}.")
sys.exit(1)
else:
# Identify the new version block
new_version_key = _find_new_version_key(fragment_dict)
if not new_version_key:
print("Error: Could not identify the new version block in the fragment.")
sys.exit(1)
new_version_data = fragment_dict[new_version_key]
# Merge unreleased notes if present
new_changes = _merge_unreleased_into_new(changelog_dict, new_version_data)
# Finalize new version in the main dictionary
changelog_dict[version] = new_changes
changelog_dict[version]["metadata"]["release_date"] = release_date
# Clear and reset unreleased section
changelog_dict["unreleased"] = {
"metadata": {
"version": "unreleased",
"release_date": None,
"url": "https://github.com/crgl-ca/hn-rt-core/compare/" + version + "...HEAD",
}
}
# Write updated changelog
new_changelog_md = keepachangelog.from_dict(changelog_dict)
with open(changelog_path, "w") as f:
f.write(new_changelog_md)
print(f"Successfully updated {changelog_path} to version {version} ({release_date}).")The inputs are the path to the changelog file (/CHANGELOG.md) and a file containing lineitems for changes, example:
v1.0.a-new-tag:
- PR #xx changed this
- PR #xy fixed that
- PR #xz new featureWhen there are trivial changes or no PRs between releases, this file will be empty.
The problem is that when you generate the changelog file using keepachangelog.from_dict(), it reads the dict values in place, appending new versions to the bottom of the file. This is contrary to the reference spec and behaviour of keepachangelog.release() outputting the versions in descending order.
Metadata
Metadata
Assignees
Labels
No labels