name: qa-required

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  qa-required:
    name: qa-required
    runs-on: ubuntu-latest
    env:
      COMPOSE_PROJECT_NAME: breadcrumb-ci

    # Phase 1: workflow is present and runnable, but branch protection does not
    # require this check yet. Enable required checks in Phase 2.
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Create .env for CI
        run: cp .env.example .env

      - name: Debug volume mount
        run: |
          echo "hostname=$(hostname)"
          docker inspect "$(hostname)" 2>/dev/null | python3 -c "
import sys,json
data=json.load(sys.stdin)
for m in data[0].get('Mounts',[]):
    print(m.get('Source'), '->', m.get('Destination'))
" || echo "inspect failed"

      - name: Start project services
        run: |
          docker compose down --remove-orphans 2>/dev/null || true
          docker compose up -d --force-recreate php db memcached
          sleep 15

      - name: Install Composer dependencies
        run: docker compose exec -T php bash -c "composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader"

      - name: Run required QA gates
        run: bin/qa-required.sh
