The purpose of this repo is to demonstrate a minimum working example of publishing to npm with a monorepo on GitHub Actions using Lerna.
- Lerna installed
- npm v7+ for package-management
- GitHub repository
- npmjs.com account
An access token is required for publishing to npm with GitHub Actions. You can create a new token by:
- Login to npmjs.com
- Click on your user icon (upper-right-hand corner)
- Select "Access Tokens" from the drop-down
- Click "Generate New Token" button
- Choose "Automation" from the options
- Copy the Access Token
With the access token created for npm, you need to create a "secret" that can be used by GitHub Actions. To add the secret:
- Click on your repo Settings
- Choose Secrets on the side menu
- Click "New Repository Secret" button
- Enter name:
NPM_TOKEN
- Enter value by pasting Access Token
- Done!
Now you are ready to publish to npm on GitHub!
In order to publish a new release run npm run release
locally, this will take you through the Lerna workflow for doing a version bump. Once that's done, your version will get tagged and pushed to GitHub.
From GitHub, create a new release using the existing tag that was pushed.
This should kick off the GitHub Actions and publish the result to npm.
There are a few small points worth noting about this setup:
- Lerna has a problem with npm 7+ which doesn't update the lock file, this creates issues on GitHub Actions by having an unclean workspace. To get around this, we manually do the tagging ourselves (see scripts/tag-release.sh).
- If using scoped packages, make sure
"publishConfig": { "access": "public" }
is added to each package, as Lerna will assume scoped packages are private by default.