name: release

on:
  release:
    types: [created]

jobs:
  test:
    runs-on: ubuntu-latest

    permissions:
      contents: read

    strategy:
      matrix:
        node-version: [20.x, 22.x, 24.x]

    steps:
      - uses: actions/checkout@v1

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}

      - name: npm install, build, and test
        run: |
          npm ci
          npm run build --if-present
          npm run lint
          npm test
        env:
          CI: true

  publish-npm:
    needs: test
    runs-on: ubuntu-latest

    permissions:
      contents: read

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 24
          registry-url: https://registry.npmjs.org/
      - run: npm ci
      - run: npm publish --access=public
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
