Generate changelog with semantic-release #963
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a script that uses semantic-release under the hood to generate the next release's changelog entry. I couldn't figure out how to work with any of the existing semantic-release plugins, so (natch) I wrote my own that implements two "steps":
analyzeCommits()
gets a list of commits (fromsemantic-release
🎉), finds the merge commits that reference PR numbers, grabs the corresponding PR data from the GitHub API, and looks at the labels for each to determine which, if any:This function then returns the release type (major, minor, or patch — I haven't tested the noop case yet) for semantic-release to manage.
generateNotes()
gets the same list of commits, figures out which ones were marked as relevant merge commits in the previous step (and which grouping they belong to), then generates a hunk of raw Markdown text to drop into the changelog.Caveats
I thought that I could get away with stashing the metadata on the commit objects in the first step, but it wasn't available in the second one. I tried using a WeakMap for the metadata (
map.set(commit, metadata)
), but none of the commit objects in the second step were found in the map. This suggests that the objects are being recreated (or deep copied?) in between steps, but I'd need to look closer at the source to know for sure.Anyway, sharing state with in a Map by commit SHA feels icky, but it works and the keys are guaranteed unique, so 🤷♂
It would probably be better to generate the changelog Markdown using an AST builder like remark.
Without further ado, here's the output, copied from this actions run:
13.2.0
🚀 Enhancements
🐛 Bug fixes
📝 Documentation
🏠 Internal
Committers