name: Quality

on:
  pull_request:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      SECRET_KEY: ci-only-secret
      NEXT_PUBLIC_SITE_URL: https://coaching-workspace.example.co
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: yarn
          cache-dependency-path: |
            backend/yarn.lock
            frontend/yarn.lock
      - name: Backend checks
        working-directory: backend
        run: yarn install --frozen-lockfile && yarn lint && yarn test
      - name: Frontend checks
        working-directory: frontend
        run: yarn install --frozen-lockfile && yarn lint && yarn typecheck && yarn build
      - name: Start frontend
        working-directory: frontend
        run: yarn start &
      - name: Accessibility checks
        working-directory: frontend
        run: |
          for attempt in $(seq 1 30); do
            if curl --fail --silent http://127.0.0.1:3000/ > /dev/null; then
              break
            fi
            sleep 1
          done
          curl --fail http://127.0.0.1:3000/ > /dev/null
          yarn a11y
