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 affectedYou will be prompted for:
- appName —
MyApp(must match your monorepo app name) - isForMonorepo —
true
Or use a config file:
json
{
"appName": "MyApp",
"isForMonorepo": true
}bash
archipelago generate affected --config affected_config.jsonStep 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 formattingStep 3: Run Affected Detection
From the monorepo root, detect packages affected by your changes:
bash
dart run devtools affected --base mainThis 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 -
doneKey Customization Points
| Customization | Where to Change |
|---|---|
| Base branch for comparison | --base flag (default: main) |
| Output format | --format flag (text, json) |
| Exclude packages from detection | affected_config.yaml exclusions list |
| Add transitive dependency tracking | dependency_graph.dart — adjust depth |
Next Steps
- Set up coverage management to test affected packages only
- Configure asset optimization as part of your CI pipeline