name: CI

on:
  push:
    branches: [main]
  pull_request:

env:
  DB_URL: sqlite://./data/ci.sqlite
  JWT_SECRET: ci-secret
  SEED_ADMIN_PASSWORD: ci-admin-pw

jobs:
  unit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci || npm install          # reproducible from the committed lockfile
      - run: npm run test:unit
      - run: cd client && (npm ci || npm install) && npm run test

  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci || npm install          # reproducible from the committed lockfile
      - run: npm run e2e:setup          # db:sync + seed:rbac + build
      - run: npx playwright install --with-deps chromium
      - run: npm run test:e2e
