# CI pipeline for Quasar (Gitea Actions)
# Jobs: build_and_test (install, prisma generate, lint, unit tests)
#       e2e (Playwright, runs on pushes to main)
# Note: `prisma generate` is allowed to continue on error to avoid blocking CI when native engines can't be built.

name: CI

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

env:
  DATABASE_URL: file:./backend/dev.db

jobs:
  build_and_test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'yarn'

      - name: Install dependencies
        run: yarn install --immutable

      - name: Install native archive tools (p7zip, chdman)
        run: |
          sudo apt-get update
          # 7z / p7zip
          sudo apt-get install -y p7zip-full p7zip-rar || true
          # chdman (intentar instalar desde paquetes disponibles: mame-tools o mame)
          sudo apt-get install -y mame-tools || sudo apt-get install -y mame || true
        continue-on-error: true

      - name: Prisma: generate (may fail on some runners)
        run: yarn workspace quasar-backend run prisma:generate
        continue-on-error: true

      - name: Lint (backend)
        run: yarn workspace quasar-backend run lint

      - name: Run backend unit tests
        run: yarn workspace quasar-backend run test:ci

  e2e:
    runs-on: ubuntu-latest
    needs: [build_and_test]
    if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'yarn'

      - name: Install dependencies
        run: yarn install --immutable

      - name: Install native archive tools (p7zip, chdman)
        run: |
          sudo apt-get update
          sudo apt-get install -y p7zip-full p7zip-rar || true
          sudo apt-get install -y mame-tools || sudo apt-get install -y mame || true
        continue-on-error: true

      - name: Install Playwright browsers
        run: yarn test:install
        continue-on-error: true

      - name: Run Playwright E2E
        run: yarn test:ci

# Metadatos
# Autor: Quasar (investigación automatizada)
# Última actualización: 2026-02-08
