Monorepo with Turborepo

Configure monorepo scopes using Turborepo for dependency-aware batching.


If you’re using monorepo tools like Turborepo that have built-in dependency graph analysis, you can leverage their affected project detection instead of using file patterns. This approach is often more accurate because these tools understand your project’s dependency relationships.

To use manual scopes mechanism, configure Mergify to expect scopes from your CI system:

scopes:
  source:
    manual:

queue_rules:
  - name: default
    batch_size: 5

Detecting Scopes with Turborepo

Section titled Detecting Scopes with Turborepo

In your GitHub Actions workflow, use the turbo run build --dry command to determine affected projects and upload them to Mergify:

name: Detect Scopes
on:
  pull_request:

jobs:
  detect-scopes:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v5

      - name: Get git refs
        id: refs
        uses: Mergifyio/gha-mergify-ci@v11
        with:
          action: git-refs

      - name: Get scopes
        id: scopes
        env:
          HEAD: ${{ steps.refs.outputs.head }}
          BASE: ${{ steps.refs.outputs.base }}
        run: |
          scopes=$(npx turbo run build --dry=json --filter="[$BASE...$HEAD]" | jq -r '.packages | join(",")')
          echo "scopes=$scopes" >> "$GITHUB_OUTPUT"

      - name: Scopes upload
        uses: Mergifyio/gha-mergify-ci@v11
        with:
          action: scopes-upload
          token: ${{ secrets.MERGIFY_TOKEN }}
          scopes: ${{ steps.scopes.outputs.scopes }}