To publish a package to npm as part of a GitHub CI (Continuous Integration) workflow, you can follow these steps:
Create an npm account:
Generate an npm token:
Add the npm token as a secret in your GitHub repository:
NPM_TOKEN
and the value set to your npm token.Configure your GitHub CI workflow:
.github/workflows/main.yml
file to define your CI workflow.- name: Publish to npm
run: |
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
npm publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Commit and push your changes:
.github/workflows/main.yml
file and push them to your GitHub repository.Now, whenever the configured events trigger the CI workflow, it will build, test, and publish your package to npm using the provided npm token.
Please note that it’s important to ensure that your CI workflow is properly configured and tested before publishing packages automatically. Additionally, make sure to update the version number in your package.json
file each time you make changes to your package to ensure proper versioning.