name: Playwright E2E

on:
  push:
    branches:
      - master
      - main
  workflow_dispatch:

concurrency:
  group: playwright-${{ github.ref }}
  cancel-in-progress: true

jobs:
  e2e:
    if: ${{ hashFiles('wiki/tiddlers/tests/playwright/**/*.ts') != '' }}
    runs-on: ubuntu-latest
    timeout-minutes: 20
    env:
      FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

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

      - name: Install Node.js
        uses: actions/setup-node@v6
        with:
          node-version: lts/*

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9
          run_install: false

      - name: Get pnpm store directory
        id: pnpm-cache
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT

      - name: Cache dependencies
        uses: actions/cache@v5
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-

      - name: Install dependencies
        run: pnpm install

      - name: Install Playwright browser
        run: pnpm exec playwright install --with-deps chromium

      - name: Run Playwright tests
        run: pnpm test:playwright

      - name: Upload Playwright report
        if: always()
        uses: actions/upload-artifact@v7
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 7
