Continuous deployments with Changesets + GitHub actions

Photo by Chris Pagan on Unsplash

Changesets is an awesome tool for versioning NPM packages and maintaining changelogs for projects, it is quickly becoming a part of all our projects, public and private alike.

The Changesets GitHub action is designed to open a pull request with a running changelog then that PR is merged to do the release. This is great when you want to control when you release to NPM, but we want to simply release to NPM as soon as a pull request with a changeset is merged.

Setup

1. Create a personal access token

GitHub actions have the GITHUB_TOKEN secret, but that token will not trigger actions when it’s used.

We have a service account we have created which we generate personal access token (PAT) for and can use when we need to work with GitHub and trigger actions.

Once you have created a PAT save it as a GitHub secret for that repo, ours is called SERVICE_ACCOUNT_PAT

2. Create main workflow

The main workflow has 2 jobs

  1. version
  2. build

version will check if there are any unreleased packages, if there is it will version them and push to master, triggering a new build

build will only run if the version job had no unreleased changes

The below gist has been annotated with the various parts

This setup minimises the changes of git conflicts as the workflow which versions will run quickly and push the new commit as soon as possible.

3. That’s it

Your NPM packages will now release as soon as something is merged to master with a changeset.

Enjoy.

--

--

--

Co-Founder featureboard.app | Principal Consultant arkahna.io | Previously Tech Lead Seven West Media WA | International Speaker | OSS | Mentor

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

VAULT deployment Kubernetes with Autounseal

Case Study | Kubernetes

Build an isometric 3D game in 2D — #4 Fall and jump

OpenEBS Node Device Management (NDM) — Troubleshooting tips

OpenEBS Node Device Management (NDM) — Troubleshooting tips

Adventures with Apache Beam

If time is money,why waste it on non value added jobs?

One small step for career, one giant step for introspection.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jake Ginnivan

Jake Ginnivan

Co-Founder featureboard.app | Principal Consultant arkahna.io | Previously Tech Lead Seven West Media WA | International Speaker | OSS | Mentor

More from Medium

How to Build a JSON RESTful API with Neo4j, PHP, and OpenAPI

Getting Started with Hot Chocolate .NET GraphQL Server

Building Multi-CPU Architecture Docker Images for ARM and x86 (2): Building in GitLab CI

Generate self signed certificates with SAN using openSSL