name: Publish npm package

on:
  release:
    types: [published]
  workflow_dispatch:

permissions:
  contents: read
  id-token: write

jobs:
  publish:
    name: Publish to npm
    runs-on: ubuntu-latest
    environment: npm
    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: 24
          registry-url: https://registry.npmjs.org
          cache: npm

      - name: Install dependencies
        run: npm ci

      - name: Verify
        run: npm run verify

      - name: Build
        run: npm run build

      - name: Smoke test npm 12 global package install
        run: npm run smoke:package-install

      - name: Publish
        run: npm publish --access public --provenance
