name: CI

on:
  push:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        php: ['7.4', '8.4']
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php }}
          tools: composer
      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: npm
      - run: composer validate --strict
      - run: composer dump-autoload --optimize --strict-psr
      - run: npm ci
      - run: npm run check
      - run: git diff --exit-code -- dist
      - run: npx playwright install --with-deps chromium
      - name: Consumer parity browser checks
        run: |
          php -S 127.0.0.1:8877 -t . > /tmp/webilia-ui-parity.log 2>&1 &
          parity_server_pid=$!
          trap 'kill "$parity_server_pid"' EXIT
          for attempt in {1..20}; do
            if curl -fsS http://127.0.0.1:8877/playground/parity.php > /dev/null; then
              npm run test:browser
              exit 0
            fi
            sleep 1
          done
          cat /tmp/webilia-ui-parity.log
          exit 1
