name: Web Full-Stack E2E

on:
  workflow_call:

permissions:
  contents: read

concurrency:
  group: web-e2e-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  test:
    name: Web Full-Stack E2E
    runs-on: depot-ubuntu-24.04-4
    defaults:
      run:
        shell: bash

    steps:
      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false

      - name: Setup web dependencies
        uses: ./.github/actions/setup-web

      - name: Setup UV and Python
        uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
        with:
          enable-cache: true
          python-version: "3.12"
          cache-dependency-glob: api/uv.lock

      - name: Install API dependencies
        run: uv sync --project api --dev

      - name: Install Playwright browser
        working-directory: ./e2e
        run: vp run e2e:install

      - name: Run isolated source-api and built-web Cucumber E2E tests
        working-directory: ./e2e
        env:
          E2E_ADMIN_EMAIL: e2e-admin@example.com
          E2E_ADMIN_NAME: E2E Admin
          E2E_ADMIN_PASSWORD: E2eAdmin12345
          E2E_FORCE_WEB_BUILD: "1"
          E2E_INIT_PASSWORD: E2eInit12345
        run: vp run e2e:full

      - name: Upload Cucumber report
        if: ${{ !cancelled() }}
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: cucumber-report
          path: e2e/cucumber-report
          retention-days: 7

      - name: Upload E2E logs
        if: ${{ !cancelled() }}
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: e2e-logs
          path: e2e/.logs
          retention-days: 7
