How to Set Up GitHub Actions to Publish a Monorepo to NPM

Cesar William Alvarenga
The Startup
Published in
3 min readAug 30, 2020

--

In my last post, I showed you how to create, test, and build a monorepo repository. In this article, I will show you how to automate the publishing of your monorepo to NPM using GitHub Actions.

What are GitHub Actions?

GitHub Actions allow for automating workflows based on repository events such as push, issue creation, or the creation of a new release.

Workflows are composed of jobs, which run concurrently by default. Each job should represent a separate part of your workflow described using steps.

For the propose of this article, we will have one job that will describe what steps must be followed to publish our package.

Config

You need to set the NPM_AUTH_TOKEN in your repo settings. This is the token the action will use to authenticate to NPM. You need to generate one in NPM, then you can add it to your secrets (settings -> secrets) so that it can be passed to the step.

Pro tip: DO NOT put the token directly in your workflow file.

Creating Our Workflow File

We will define our workflow by creating a YAML file.

--

--