name: Node.js Package
on: [push]

permissions:
  contents: write
  id-token: write

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: 25
      - uses: pnpm/action-setup@v6
        with:
          # No `version:` — defer to packageManager in package.json.
          run_install: false
      - name: Get pnpm store directory
        shell: bash
        run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
      - uses: actions/cache@v5
        with:
          path: ${{ env.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-
      - run: pnpm install --frozen-lockfile
      - run: pnpm test
  release:
    if: ${{ github.ref == 'refs/heads/main' }}
    needs: test
    permissions:
      contents: write
      id-token: write
    uses: ./.github/workflows/npmpublish.yml
    secrets: inherit
