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

Generate changelog with semantic-release #963

Merged
merged 7 commits into from
Nov 5, 2019

Conversation

shawnbot
Copy link
Contributor

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":

  1. analyzeCommits() gets a list of commits (from semantic-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:

    • correspond to a semver release type (patch, minor, or major) and
    • map to one of our predefined change categories (breaking, enhancement, bug fix, polish, or internal)

    This function then returns the release type (major, minor, or patch — I haven't tested the noop case yet) for semantic-release to manage.

  2. 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

  • #959 More buttons
  • #950 Add Diffstat component
  • #913 Importing TimelineItem from .com and creating matching docs
  • #953 Add IssueLabel component

🐛 Bug fixes

  • #945 Add [role=tab][aria-selected=true] to .UnderlineNav-item.selected

📝 Documentation

  • #939 Fix Box--overlay example
  • #943 Fix broken links to typography utilities

🏠 Internal

  • #946 Add TODO@version stylelint rule (local)

Committers

@vercel
Copy link

vercel bot commented Oct 28, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/primer/primer-css/g9xfr863j
🌍 Preview: https://primer-css-git-generate-changelog.primer.now.sh

Copy link
Contributor

@simurai simurai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output looks pretty good. ✨ Like hand made.

@shawnbot shawnbot changed the base branch from release-13.2.0 to release-14.0.0 November 1, 2019 19:05
@shawnbot
Copy link
Contributor Author

shawnbot commented Nov 1, 2019

Let's test this out on the 14.0 release!

@shawnbot shawnbot marked this pull request as ready for review November 1, 2019 19:06
@shawnbot shawnbot merged commit 0cde1c4 into release-14.0.0 Nov 5, 2019
@shawnbot shawnbot mentioned this pull request Nov 5, 2019
19 tasks
@shawnbot shawnbot deleted the generate-changelog branch November 5, 2019 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants