name: Validate Explorer

on:
  pull_request:
    branches: [main, master]
    paths:
      - '.gitea/workflows/validate-on-pr.yml'
      - 'frontend/**'
      - 'scripts/e2e-*.spec.ts'
      - 'package.json'
      - 'package-lock.json'
      - 'playwright.config.ts'
  push:
    branches: [main, master]
    paths:
      - '.gitea/workflows/validate-on-pr.yml'
      - 'frontend/**'
      - 'scripts/e2e-*.spec.ts'
      - 'package.json'
      - 'package-lock.json'
      - 'playwright.config.ts'

jobs:
  frontend:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: frontend
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: npm
          cache-dependency-path: frontend/package-lock.json

      - name: Install dependencies
        run: npm ci

      - name: Lint, type-check, and unit tests
        run: npm test

  smoke-e2e:
    runs-on: ubuntu-latest
    needs: frontend
    if: github.event_name == 'push'
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: npm
          cache-dependency-path: package-lock.json

      - name: Install root dependencies
        run: npm ci

      - name: Install Playwright browser
        run: npx playwright install chromium

      - name: Run live sprint smoke tests
        env:
          EXPLORER_URL: https://explorer.d-bis.org
        run: npm run e2e -- scripts/e2e-sprint-smoke.spec.ts
