Skip to content

Setting Up Affected Package Detection

What you'll learn

  • Generating the affected command for your monorepo toolkit
  • Detecting which packages changed based on git diff
  • Integrating affected detection into CI/CD pipelines
  • Skipping unchanged packages to speed up builds

Prerequisites

  • An existing Archipelago monorepo (see Monorepo Scaffolding)
  • A monorepo_toolkit already generated at devtools/

Step 1: Generate the Affected Command

bash
archipelago generate affected

You will be prompted for:

  • appNameMyApp (must match your monorepo app name)
  • isForMonorepotrue

Or use a config file:

json
{
  "appName": "MyApp",
  "isForMonorepo": true
}
bash
archipelago generate affected --config affected_config.json

Step 2: Understand the Generated Structure

The brick adds the affected command to your existing monorepo toolkit:

devtools/
└── lib/src/
    └── commands/
        └── affected/
            ├── affected_command.dart        # CLI entry point
            ├── dependency_graph.dart         # Package dependency resolver
            ├── git_diff_resolver.dart        # Git-based change detection
            └── affected_reporter.dart        # Output formatting

Step 3: Run Affected Detection

From the monorepo root, detect packages affected by your changes:

bash
dart run devtools affected --base main

This compares your current branch against main and outputs a list of packages that have changed or depend on changed packages.

Step 4: Use in CI/CD

Integrate affected detection into your GitHub Actions workflow to skip unchanged packages:

yaml
- name: Detect affected packages
  id: affected
  run: dart run devtools affected --base origin/main --format json > affected.json

- name: Test affected packages
  run: |
    for pkg in $(jq -r '.[]' affected.json); do
      cd "$pkg" && flutter test && cd -
    done

Key Customization Points

CustomizationWhere to Change
Base branch for comparison--base flag (default: main)
Output format--format flag (text, json)
Exclude packages from detectionaffected_config.yaml exclusions list
Add transitive dependency trackingdependency_graph.dart — adjust depth

Next Steps

Built by Banua Coder