Use GitHub actions to publish your package on NPM
Recently, I created a package with the ESLint settings I like to use in my React projects, as I was tired of always having to configure it when I start new React projects. Publishing a NPM package is just a matter of running npm publish
on the directory of your package (considering, of course, that you already have an NPM account and is authenticated on your terminal). But I wanted to automatize this publishing everytime I created a new release.
In order to do that, I used the following GitHub Action:
If you read the YAML file above (that you should put on the .github/workflows/npm-publish.yml
directory of your git repository), you should have noted that the environment variable NODE_AUTH_TOKEN
should be defined. Create a new automation access token on the control panel of NPM:
-
Access your NPM account and click in "Access tokens":
-
Name your new access token and select the "Automation" type for it:
- Go to your GitHub repository, click in "Settings > Secrets > Actions > New repository secret", name it as NODE_AUTH_TOKEN and paste the access token you just got from NPM:
- Create a new release for your package. This should trigger our GitHub Action and publish to NPM.