name: Playwright Tests

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

jobs:
  test:
    timeout-minutes: 60
    runs-on: ubuntu-latest

    steps:
      # Checkout repository
      - uses: actions/checkout@v3

      # Set up Node.js with cache
      - uses: actions/setup-node@v3
        with:
          node-version: 20.18.0
          cache: 'npm'

      # Install dependencies
      - name: Install dependencies
        run: |
          export NODE_ENV=production
          npm ci --legacy-peer-deps

      # Install Playwright browsers
      - name: Install Playwright Browsers
        run: npx playwright install --with-deps

      # Run Playwright tests with a specific reporter
      - name: Run Playwright Tests
        run: npx playwright test --reporter=html

      # Upload Playwright HTML report
      - uses: actions/upload-artifact@v3
        if: ${{ always() }} # Always upload, even if tests fail
        with:
          name: playwright-report
          path: playwright-report/
          retention-days: 30
