Publish to npm #1
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: | |
| permissions: | |
| contents: read | |
| id-token: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| registry-url: https://registry.npmjs.org | |
| - name: Use npm with trusted publishing support | |
| run: npm install -g npm@11 | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Check release tag | |
| if: github.event_name == 'release' | |
| run: | | |
| package_version=$(node -p "require('./package.json').version") | |
| tag_version="${GITHUB_REF_NAME#v}" | |
| if [ "$package_version" != "$tag_version" ]; then | |
| echo "Release tag ($GITHUB_REF_NAME) does not match package.json version ($package_version)." | |
| exit 1 | |
| fi | |
| - name: Type-check | |
| run: npm run check | |
| - name: Build | |
| run: npm run build | |
| - name: Publish | |
| run: npm publish --provenance |