name: Test & Build

on:
  pull_request:
    branches: [main]
    types: [opened, synchronize, reopened, ready_for_review]

concurrency:
  group: test-build-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  test-build:
    name: Test & Build
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest
    timeout-minutes: 15

    env:
      CI: true
      HEADLESS: 1
      VITE_SUPABASE_URL: http://127.0.0.1:54321
      VITE_SUPABASE_ANON_KEY: ci-anon-key
      VITE_SUPABASE_SOURCE_FILES_BUCKET: source-files
      SUPABASE_URL: http://127.0.0.1:54321
      SUPABASE_ANON_KEY: ci-anon-key
      SUPABASE_SERVICE_ROLE_KEY: ci-service-role-key

    steps:
      - uses: actions/checkout@v4

      - uses: pnpm/action-setup@v4
        with:
          version: 10.28.2
          run_install: false

      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: pnpm

      - run: pnpm install --frozen-lockfile
      - run: pnpm lint
      - run: pnpm test
      - run: pnpm build
