Publish NPM Package #20
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 NPM Package | |
| on: | |
| push: | |
| tags: | |
| - 'js-v*' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| id-token: write | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| publish-npm: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v5 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: 24 | |
| registry-url: https://registry.npmjs.org | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Run tests | |
| run: npm test | |
| - name: Verify tag matches package version | |
| if: startsWith(github.ref, 'refs/tags/') | |
| env: | |
| GITHUB_REF_NAME: ${{ github.ref_name }} | |
| run: | | |
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
| EXPECTED_TAG="js-v${PACKAGE_VERSION}" | |
| if [ "$GITHUB_REF_NAME" != "$EXPECTED_TAG" ]; then | |
| echo "Tag $GITHUB_REF_NAME does not match package version $PACKAGE_VERSION" | |
| exit 1 | |
| fi | |
| - name: Publish to npm | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: npm publish --access public --provenance |