name: 🎭 E2E Tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
    paths:
      - "e2e/**"
      - ".github/workflows/e2e-tests.yml"

jobs:
  e2e-tests:
    name: 🎭 Run E2E Tests
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

      - name: Setup Bun
        uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2

      - name: Install dependencies
        run: |
          cd e2e
          bun install

      - name: Install Playwright browsers
        run: |
          cd e2e
          bunx playwright install --with-deps

      - name: Install uv
        uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
        with:
          enable-cache: true
          python-version: "3.12"

      - name: Install Python dependencies
        run: |
          uv sync --extra cli
          uv pip install graphql-core==3.3.0a12

      - name: Start Strawberry server
        run: |
          cd e2e
          # --no-sync prevents uv from reverting graphql-core to lockfile version
          uv run --no-sync strawberry dev app:schema --port 8000 &
          echo $! > server.pid
          sleep 5  # Wait for server to start

      - name: Check if server is running
        run: |
          curl -f http://localhost:8000/graphql || (echo "Server is not running" && exit 1)
          echo "GraphQL server is running successfully"

      - name: Run Playwright tests
        run: |
          cd e2e
          bunx playwright test

      - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
        if: always()
        with:
          name: playwright-report
          path: e2e/playwright-report/
          retention-days: 30
