name: Electron E2E

on:
  workflow_dispatch:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

jobs:
  electron-e2e:
    name: Electron E2E (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    timeout-minutes: 20
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
    env:
      CI: 'true'

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Setup pnpm
        uses: pnpm/action-setup@v4

      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: '24'
          cache: 'pnpm'

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Rebuild Electron binary
        run: pnpm rebuild electron

      - name: Run Electron E2E on Linux
        if: runner.os == 'Linux'
        run: xvfb-run -a pnpm run test:e2e

      - name: Run Electron E2E on macOS
        if: runner.os == 'macOS'
        run: pnpm run test:e2e

      - name: Run Electron E2E on Windows
        if: runner.os == 'Windows'
        run: pnpm run test:e2e

      - name: Upload Playwright artifacts
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: playwright-artifacts-${{ matrix.os }}
          path: |
            playwright-report
            test-results
          if-no-files-found: warn
          retention-days: 7
