swyxio / swyxdotio

This is the repo for swyx's blog - Blog content is created in github issues, then posted on swyx.io as blog pages! Comment/watch to follow along my blog within GitHub
https://swyx.io
MIT License
336 stars 45 forks source link

Semi-Automatic npm and GitHub Releases with `gh-release` and `auto-changelog` #343

Closed swyxio closed 2 years ago

swyxio commented 2 years ago

source: devto devToUrl: "https://dev.to/swyx/semi-automatic-npm-and-github-releases-with-gh-release-and-auto-changelog-4b5a" devToReactions: 38 devToReadingTime: 2 devToPublishedAt: "2020-07-17T18:57:45.109Z" devToViewsCount: 397 title: Semi-Automatic npm and GitHub Releases with gh-release and auto-changelog published: true description: A snippet I use all the time tags: JavaScript slug: release-automation canonical_url: https://www.swyx.io/writing/release-automation

This is a blogpost I've been sitting on for over 1 yr because I haven't had the time to really study all the approaches and decide on the best one.

Kent C. Dodds is notable for setting up fully automated releases for all his OSS libraries. I think that is good for high volumes of releases, but it does involve extra setup steps that may not be worth it for smaller, more casual libraries.

I picked up this semi-automatic method from Bret Comnes at Netlify and I quite like it. Writing it down since I refer to it approximately once a month.

Steps

Given a library you want to automate releases of:

npm i -D auto-changelog gh-release

add npm scripts:

{
  "scripts": {
     "version": "auto-changelog -p --template keepachangelog && git add CHANGELOG.md",
     "prepublishOnly": "git push && git push --tags && gh-release"
  }
}

Now whenever you want to cut a new release:

Why

Using GitHub releases is a nice best practice for people watching your repo but also if you have any downloadable artifacts people can grab it right off your GitHub.

You retain manual control of your CHANGELOG and your publish process, while automating the boring parts of pushing releases and generating the base changelog. Also no extra npm tokens or infrastructure need be setup to do this, it's all done on your own machine.

More advice

I advise adding a prepublish script to run builds and tests as well - I have been caught a couple times publishing bad versions because I forgot these in some packages.

This is NOT the last word on how best to automate releases - this is just what works for me now, but I have a LONG list of other methods to investigate but not enough time to try them all out right now.

Related writing from me: Best Practice Open Source Repo Setup

Here's a list of release tech I have yet to try out but made notes of: