name: Build & Test

on:
  workflow_call:
    secrets:
      npm_token:
        required: true

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [ 18, 20, 21, 22.5.1 ]

    steps:
      - uses: actions/checkout@v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - name: generate NPMRC file
        run:
          echo "//registry.npmjs.org/:_authToken=${{ secrets.npm_token }}" > .npmrc

      - name: Install dependencies
        run: yarn

      - name: Build the lib
        run: yarn build

      - name: Run tests
        run: yarn test
