name: Quality Gates (pnpm)

on:
  push:
    branches:
      - main
    paths:
      - '**/*.ts'
      - '**/*.vue'
      - '**/*.js'
      - 'package.json'
      - 'pnpm-lock.yaml'
      - '**/tsconfig.json'
      - '.github/workflows/quality-gates-pnpm.yml'

jobs:
  gates:
    runs-on: ubuntu-latest
    timeout-minutes: 30

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          run_install: false
          package_json_path: package.json

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

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Type check (monorepo)
        run: pnpm type-check

      - name: Run unit tests
        run: pnpm test -- --coverage

      - name: Validate quality script
        run: |
          chmod +x ./scripts/validate-quality.sh || true
          ./scripts/validate-quality.sh

      - name: Upload coverage (artifact)
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: coverage-artifacts
          path: |
            **/coverage/**
          if-no-files-found: ignore
