name: Type Check

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

jobs:
  type-check:
    runs-on: ubuntu-latest
    
    strategy:
      matrix:
        project:
          - name: api
            directory: api
          - name: portal
            directory: portal
          - name: root
            directory: .

    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: 'npm'
          cache-dependency-path: ${{ matrix.project.directory }}/package-lock.json
      
      - name: Install dependencies
        working-directory: ${{ matrix.project.directory }}
        run: |
          if [ -f "package.json" ]; then
            npm ci
          fi
      
      - name: Type check
        working-directory: ${{ matrix.project.directory }}
        run: |
          if [ -f "tsconfig.json" ]; then
            npx tsc --noEmit
          fi

