name: Build and Test
on: [push, pull_request]

# Declare default permissions as read only.
permissions: read-all

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout 🛎️
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false

      - name: Use Node.js
        uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
        with:
          node-version: 22
          cache: npm

      - name: Node & Npm Version
        run: |
          node -v
          npm -v
          
      - name: Verify lockfile is up to date
        run: |
          npm install --package-lock-only --no-audit --no-fund
          git diff --exit-code || (echo "Lockfile not up to date. Run 'npm i' and commit the changes." && exit 1)
          
      - name: Install 🔧
        run: npm ci --no-audit --no-fund

      - name: Test 🚨
        run: npm run test
