Publish package to npm #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish package to npm | |
| # The workflow needs to be started manually | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_tag: | |
| description: 'Optional npm tag (e.g. beta, next)' | |
| required: false | |
| default: 'latest' | |
| jobs: | |
| publish: | |
| name: Publish to npm | |
| runs-on: ubuntu-latest | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '22' | |
| registry-url: 'https://registry.npmjs.org' | |
| # Note that deleting package-lock.json is a workaround for an npm issue related to | |
| # optional dependencies: https://github.com/npm/cli/issues/4828 | |
| - name: Build the project | |
| run: | | |
| rm package-lock.json | |
| npm install | |
| npm run build | |
| - name: Publish to npm | |
| id: publish | |
| run: | | |
| npm publish --tag ${{ github.event.inputs.version_tag || 'latest' }} | |
| PUBLISHED_VERSION=$(node -p "require('./package.json').version") | |
| echo "published_version=$PUBLISHED_VERSION" >> $GITHUB_OUTPUT | |
| - name: Output published version | |
| run: | | |
| echo "Successfully published version: ${{ steps.publish.outputs.published_version }}" |