Use GitHub actions to publish your package on NPM
![Use GitHub actions to publish your package on NPM](/_next/image?url=https%3A%2F%2Fpocketbase.douglasmoura.dev%2Fapi%2Ffiles%2Fquq9xznky3sx782%2Fvexiz92e4b6be18%2Flula_62mvAztOea.jpg&w=3840&q=75)
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.