name: End-to-end tests (playwright)
on:
  push:
    branches: [ main ]
    paths:
      - 'src/**'
      - 'test-e2e/**'
      - 'package-lock.json'
      - '.browserslistrc'
      - 'babel.config.json'
      - 'public/index.html'
      - 'public/**/index.html'
      - '.github/workflows/browsers.yml'
      - 'playwright.config.ts'
  pull_request:
    paths:
      - 'src/**'
      - 'test-e2e/**'
      - 'package-lock.json'
      - '.browserslistrc'
      - 'babel.config.json'
      - 'public/index.html'
      - 'public/**/index.html'
      - '.github/workflows/browsers.yml'
      - 'playwright.config.ts'
jobs:
  test-e2e-playwright:
    timeout-minutes: 60
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, macos-latest, ubuntu-latest]
        browser: [chromium, firefox, webkit]
        exclude:
          - os: windows-latest
            browser: webkit
          - os: windows-latest
            browser: firefox
          - os: macos-latest
            browser: firefox
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 1

    - uses: actions/setup-node@v4
      with:
        node-version: 24
        cache: 'npm'

    - name: Install dependencies
      run: npm ci --no-audit
    - name: Install Playwright Browsers
      run: npx playwright install --with-deps
    - run: npx playwright install-deps

    - name: Run Playwright tests
      run: npx playwright test --project=${{ matrix.browser }}

    - uses: actions/upload-artifact@v4
      name: Upload screenshots to GitHub Actions Artifacts
      if: failure()
      with:
        name: screenshot-${{ matrix.os }}-${{ matrix.browser }}
        path: test-results/**/*.png

    - uses: actions/upload-artifact@v4
      name: Upload blob report to GitHub Actions Artifacts
      if: ${{ !cancelled() }}
      with:
        name: playwright-report-${{ matrix.os }}-${{ matrix.browser }}
        path: playwright-report/
        retention-days: 30