# Pre-PR Build Checks

## Multi-Runtime Detection

```bash
# Build check (multi-runtime detection)
echo "Running build check..."
if [ -f "*.sln" ] || ls *.csproj 2>/dev/null | head -1 > /dev/null; then
  dotnet build --no-restore 2>&1 || {
    echo "❌ .NET build failed. Fix before creating PR."
    STOP
  }
  # Migration check
  echo "Checking migrations..."
  dotnet ef migrations list 2>&1 || echo "No migrations or EF Core not configured"
elif [ -f "package.json" ]; then
  npm run build 2>&1 || {
    echo "❌ npm build failed. Fix before creating PR."
    STOP
  }
elif [ -f "requirements.txt" ] || [ -f "pyproject.toml" ]; then
  echo "Python project detected — skipping build check"
else
  echo "⚠️ No known build system detected — skipping build check"
fi
```

## Enforce Migration Squash (Feature Branches)

**BLOCKING**: Feature branches must have at most 1 migration before creating a PR.

```bash
if [ "$BRANCH_TYPE" = "feature" ]; then
  MIGRATION_DIR=$(find . -path "*/Persistence/Migrations" -type d 2>/dev/null | head -1)
  if [ -n "$MIGRATION_DIR" ]; then
    # Count migration .cs files added by this feature (not in target branch)
    NEW_MIGRATIONS=$(git diff --name-only "origin/$TARGET_BRANCH...HEAD" -- "$MIGRATION_DIR" \
      | grep -E '\.cs$' \
      | grep -v 'Designer\|ModelSnapshot' \
      | wc -l)

    if [ "$NEW_MIGRATIONS" -gt 1 ]; then
      echo ""
      echo "❌ MULTIPLE MIGRATIONS DETECTED ($NEW_MIGRATIONS migrations)"
      echo "→ Feature branches must have exactly 1 migration (squashed) before PR"
      echo "→ Run: /efcore squash"
      echo ""
      echo "Migrations found:"
      git diff --name-only "origin/$TARGET_BRANCH...HEAD" -- "$MIGRATION_DIR" \
        | grep -E '\.cs$' \
        | grep -v 'Designer\|ModelSnapshot'
      STOP
    elif [ "$NEW_MIGRATIONS" -eq 1 ]; then
      echo "✓ Single migration detected (squashed)"
    else
      echo "✓ No migrations in this feature"
    fi
  fi
fi
```
