name: Run E2E Playwright tests
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  e2e-test:
    name: E2E Test
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version-file: extensions/ql-vscode/.nvmrc
          cache: 'npm'
          cache-dependency-path: extensions/ql-vscode/package-lock.json

      - name: Install dependencies
        working-directory: extensions/ql-vscode
        run: npm ci

      - name: Start containers
        working-directory: extensions/ql-vscode/test/e2e
        run: docker-compose -f "docker-compose.yml" up -d --build

      - name: Install Playwright Browsers
        working-directory: extensions/ql-vscode
        run: npx playwright install --with-deps
      - name: Run Playwright tests
        working-directory: extensions/ql-vscode/test/e2e
        run: npx playwright test
      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: playwright-report
          path: extensions/ql-vscode/playwright-report/
          retention-days: 30
      - name: Stop containers
        working-directory: extensions/ql-vscode/test/e2e
        if: always()
        run: docker-compose -f "docker-compose.yml" down -v
