Publish to npm #7
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 to npm | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: Release tag to publish (for example, v0.2.2) | |
| required: true | |
| default: v0.2.2 | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: actions/setup-node@v7 | |
| with: | |
| node-version: 20 | |
| registry-url: https://registry.npmjs.org | |
| cache: npm | |
| - name: Verify tag matches package.json version | |
| run: | | |
| TAG_VERSION="${GITHUB_REF_NAME#v}" | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| TAG_VERSION="${{ inputs.tag }}" | |
| TAG_VERSION="${TAG_VERSION#v}" | |
| fi | |
| PKG_VERSION="$(node -p "require('./package.json').version")" | |
| if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then | |
| echo "::error::Release tag v$TAG_VERSION does not match package.json version $PKG_VERSION" | |
| exit 1 | |
| fi | |
| - run: npm ci | |
| - name: Publish (beta) | |
| if: github.event.release.prerelease == true | |
| run: npm publish --tag beta --access public | |
| - name: Publish (stable) | |
| if: github.event_name == 'workflow_dispatch' || github.event.release.prerelease == false | |
| run: npm publish --tag latest --access public |