Affected Package Detection Enterprise
The affected command detects which workspace packages are impacted by git changes and runs commands only on those packages. This dramatically speeds up CI pipelines by skipping unchanged packages.
Usage
# List affected packages
dart run monorepo_toolkit affected list
# Run analysis on affected packages only
dart run monorepo_toolkit affected analyze
# Run tests on affected packages only
dart run monorepo_toolkit affected test --coverage
# Run any command on affected packages
dart run monorepo_toolkit affected run -- "dart format --set-exit-if-changed ."Subcommands
affected list
Lists packages affected by git changes compared to a base branch:
dart run monorepo_toolkit affected list --base develop
dart run monorepo_toolkit affected list --format plain # CI-friendly output| Flag | Abbr | Default | Description |
|---|---|---|---|
--base | -b | main | Base branch or commit to compare against |
--format | -f | pretty | Output format: pretty or plain |
--json | -j | false | Output as JSON array for GitHub Actions matrix |
affected analyze
Runs flutter analyze lib on affected packages:
dart run monorepo_toolkit affected analyze --base develop
dart run monorepo_toolkit affected analyze --no-fail-fast| Flag | Abbr | Default | Description |
|---|---|---|---|
--base | -b | main | Base branch or commit to compare against |
--fail-fast | true | Stop on first package failure |
affected test
Runs flutter test on affected packages with optional coverage collection:
dart run monorepo_toolkit affected test --coverage --base develop| Flag | Abbr | Default | Description |
|---|---|---|---|
--base | -b | main | Base branch or commit to compare against |
--coverage | false | Collect coverage information | |
--fail-fast | true | Stop on first package failure | |
--total-shards | — | — | Total number of shards for within-package test splitting |
--shard-index | — | — | Zero-based index of this shard (requires --total-shards) |
affected run
Runs an arbitrary command on affected packages:
dart run monorepo_toolkit affected run -- "flutter test --coverage"
dart run monorepo_toolkit affected run -- "dart format --set-exit-if-changed ."| Flag | Abbr | Default | Description |
|---|---|---|---|
--base | -b | main | Base branch or commit to compare against |
--fail-fast | true | Stop on first package failure |
Configuration
Create an affected.yaml at the workspace root:
affected:
base_branch: develop
# Predefined commands (merged with defaults: analyze, test, format)
commands:
lint: "dart run custom_lints ."
# Packages always included regardless of changes
always_include:
- template_app
# Glob patterns to ignore when detecting changes
ignore:
- "devtools/**"
- ".github/**"
- ".claude/**"The default ignore patterns are devtools/**, .github/**, and .claude/**. The default predefined commands are analyze (flutter analyze lib), test (flutter test), and format (dart format --set-exit-if-changed .).
CI integration
steps:
- name: Analyze affected packages
run: dart run monorepo_toolkit affected analyze --base origin/develop
- name: Test affected packages
run: dart run monorepo_toolkit affected test --coverage --base origin/developGitHub Actions Matrix (CI Parallelism)
Use affected list --json to feed a dynamic matrix into GitHub Actions, so each affected package is tested in its own parallel job.
jobs:
detect:
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.affected.outputs.packages }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dart-lang/setup-dart@v1
- name: Detect affected packages
id: affected
run: |
PACKAGES=$(dart run monorepo_toolkit affected list --json --base origin/develop)
echo "packages=$PACKAGES" >> "$GITHUB_OUTPUT"
test:
needs: detect
if: ${{ needs.detect.outputs.packages != '[]' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package: ${{ fromJSON(needs.detect.outputs.packages) }}
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
- name: Test ${{ matrix.package }}
run: dart run monorepo_toolkit affected test --base origin/developThe --json flag outputs a JSON array of package names (e.g. ["auth_impl","ui_kit"]). GitHub's fromJSON() function expands this into the matrix, creating one job per affected package automatically. See ci-affected-matrix.yml.example in the generated project's .github/workflows/ directory for the full annotated example.