name: E2E Tests

on:
  push:
    branches-ignore:
      - 'build'
    paths:
      - 'src/**'
      - 'e2e/**'
      - 'build/**'
      - 'package.json'
      - 'package-lock.json'
      - '.github/workflows/e2e.yml'
  pull_request:

permissions:
  contents: read

jobs:
  e2e:
    runs-on: ubuntu-latest
    timeout-minutes: 30

    steps:
      - name: Checkout code
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
        with:
          persist-credentials: false

      - name: Setup Node.js
        uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
        with:
          node-version: '24'
          package-manager-cache: true

      - run: npm ci

      - name: Build SDK bundle
        run: npm run build:sdk

      - name: Install Playwright Chromium
        run: npx playwright install --with-deps chromium

      - name: Run E2E suite
        run: npm run test:e2e
        env:
          E2E_GL: swiftshader

      - name: Upload report and traces
        if: failure()
        uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
        with:
          name: e2e-report
          path: |
            e2e/playwright-report/
            e2e/test-results/
          retention-days: 7
