Publish NPM
Packages via GitHub actions Workflow
To get Started you should have npm
and GitHub
accounts. If you don’t have any of the accounts please create.
Please follow the below steps to publish your npm
package via GitHub
action workflows.
- Create a GitHub repository and place your JavaScript library in it.
2. Make sure you add package.json
and package-lock.json
to the repo with all npm related properties. name
property should as follows for scoped packages @{npm username}/{package name}
. For non-scoped packages you don’t need to maintain @{npm username}/
in name property. You can directly provide package name
`.
Scoped package : { “name”: “@vasuvanka/jsutils”}
Non-Scoped package : { “name”: “jsutils” }
3. Need an npm secret token which will be used to publish our package into npm registry. To generate secret please follow the below steps
a) Login into npm
b) Click on Profile logo -> Auth Tokens and then click on Create New Token with read , publish access.
c) Copy generated token.
d) Go to your GitHub repo settings -> Secrets -> click on Add a new secret.
e) Now Add Secret key Name
as NPM_SECRET
and paste copied npm secret key as value
and then click Add secret.
4. We are now done with npm secret key configuration. Will get into actions work flow now. Go to GitHub actions -> New workflow -> choose Publish Node.js package and make edit file with following changes
- run: npm publish — access=public
Add — access=public to make your npm package available to public
NODE_AUTH_TOKEN: ${{secrets.NPM_SECRET}}
Replace scope with your GitHub username
scope: ‘@vasuvanka’
Now we are done with Workflow changes.
5. To Publish our npm package we need to push the release from GitHub. Go to Releases on your GitHub repo page and the click on Draft a new release.
Specify Version starts with v0.0.1
or whatever your are wishing to.
Add title, description and check if it is pre-release and then click on publish.
Yahoooo! Your package will be appeared in npm registry.
Here is the GitHub repo for reference https://github.com/vasuvanka/jsutils