From d98be7992cc92802b05fe7738847249fb1660a92 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 23 Sep 2026 00:23:45 +0530 Subject: [PATCH 1/2] ci: test only changed packages and their dependents Select packages with melos list --diff --include-dependents and pass them to tools/coverage.py. Gate the macOS native job on contact_permission. Shared workspace inputs or an unknown base still run everything. Co-Authored-By: Claude Opus 5.5 (1M context) --- .github/workflows/dart.yml | 44 ++++++++++++++++++++++++++++++++++++-- docs/testing.md | 2 ++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index a279741..4093a9b 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -10,7 +10,39 @@ env: FLUTTER_VERSION: "3.47.5" jobs: + # Test only packages changed since the base (plus their dependents). Shared + # workspace inputs, or an unknown base, fall back to testing everything. + changes: + runs-on: ubuntu-latest + outputs: + packages: ${{ steps.select.outputs.packages }} + all: ${{ steps.select.outputs.all }} + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ env.FLUTTER_VERSION }} + cache: true + - run: flutter pub get --enforce-lockfile + - id: select + env: + BASE: ${{ github.event_name == 'pull_request' && format('origin/{0}', github.base_ref) || github.event.before }} + run: | + if [[ -z "$BASE" || "$BASE" =~ ^0+$ ]] || ! git cat-file -e "$BASE^{commit}" 2>/dev/null \ + || git diff --name-only "$BASE" HEAD | grep -qE '^(pubspec\.(yaml|lock)|analysis_options\.yaml|test/|tools/(coverage\.py|tests/|[^/]+\.dart)|\.github/workflows/dart\.yml)'; then + echo "all=true" >> "$GITHUB_OUTPUT" + echo "Testing all packages" + else + packages=$(dart run melos list --diff="$BASE" --include-dependents --parsable --relative | xargs) + echo "all=false" >> "$GITHUB_OUTPUT" + echo "packages=$packages" >> "$GITHUB_OUTPUT" + echo "Testing: ${packages:-nothing}" + fi + quality: + needs: changes runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -27,8 +59,14 @@ jobs: run: python3 -m unittest discover -s tools/tests - name: Check formatting and analyze workspace run: dart run melos run lint - - name: Require 100% coverage in every package - run: python3 tools/coverage.py + - name: Require 100% coverage in changed packages + if: needs.changes.outputs.all == 'true' || needs.changes.outputs.packages != '' + env: + PACKAGES: ${{ needs.changes.outputs.packages }} + run: | + args=() + for package in $PACKAGES; do args+=(--package "$package"); done + python3 tools/coverage.py "${args[@]}" - name: Save test logs and coverage reports if: always() uses: actions/upload-artifact@v7 @@ -41,6 +79,8 @@ jobs: tools/**/coverage/ native-permissions: + needs: changes + if: needs.changes.outputs.all == 'true' || contains(format(' {0} ', needs.changes.outputs.packages), ' plugins/contact_permission ') runs-on: macos-latest timeout-minutes: 30 steps: diff --git a/docs/testing.md b/docs/testing.md index 7b9480f..6f7d966 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -24,6 +24,8 @@ python3 tools/coverage.py --package ns_utils python3 tools/coverage.py --package packages/timer_button/example ``` +CI tests only the packages changed since the base commit, plus their workspace dependents (`melos list --diff= --include-dependents`). The native permission job runs only when `contact_permission` is selected. Changes to shared inputs (root `pubspec.yaml`/`pubspec.lock`, `analysis_options.yaml`, root `test/`, `tools/coverage.py`, `tools/tests/`, root `tools/*.dart`, or the Dart workflow) run every package. Formatting and analysis always cover the whole workspace. + `--report-only` inspects existing reports and writes `summary-existing.json`; it does not establish a fresh passing result. Mustache brick source is not runnable Dart until rendered. The separate generated-template workflow renders representative module combinations, analyzes them, and requires 100% handwritten Dart coverage inside the generated workspace. The template contract suite additionally validates every module selection. Hook bundles exclude local tests/build artifacts and workspace-only `resolution` metadata. From 226bd3735a68bdd124aef46c7ef7c8288a3dd1f4 Mon Sep 17 00:00:00 2001 From: Ajay Kumar Date: Wed, 23 Sep 2026 00:40:42 +0530 Subject: [PATCH 2/2] ci: run package tests as a parallel matrix Each selected package gets its own job with fail-fast disabled, so independent packages test concurrently instead of sequentially. Co-Authored-By: Claude Opus 5.5 (1M context) --- .github/workflows/dart.yml | 56 +++++++++++++++++++++++++------------- docs/testing.md | 2 +- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 4093a9b..75ea0a1 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -16,7 +16,6 @@ jobs: runs-on: ubuntu-latest outputs: packages: ${{ steps.select.outputs.packages }} - all: ${{ steps.select.outputs.all }} steps: - uses: actions/checkout@v7 with: @@ -32,17 +31,15 @@ jobs: run: | if [[ -z "$BASE" || "$BASE" =~ ^0+$ ]] || ! git cat-file -e "$BASE^{commit}" 2>/dev/null \ || git diff --name-only "$BASE" HEAD | grep -qE '^(pubspec\.(yaml|lock)|analysis_options\.yaml|test/|tools/(coverage\.py|tests/|[^/]+\.dart)|\.github/workflows/dart\.yml)'; then - echo "all=true" >> "$GITHUB_OUTPUT" - echo "Testing all packages" + packages=$(dart pub workspace list --json | jq -c --arg root "$PWD" \ + '[.packages[].path | if . == $root then "." else ltrimstr($root + "/") end]') else - packages=$(dart run melos list --diff="$BASE" --include-dependents --parsable --relative | xargs) - echo "all=false" >> "$GITHUB_OUTPUT" - echo "packages=$packages" >> "$GITHUB_OUTPUT" - echo "Testing: ${packages:-nothing}" + packages=$(dart run melos list --diff="$BASE" --include-dependents --parsable --relative | jq -Rsc 'split("\n") | map(select(. != ""))') fi + echo "packages=$packages" >> "$GITHUB_OUTPUT" + echo "Testing: $packages" quality: - needs: changes runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -59,28 +56,49 @@ jobs: run: python3 -m unittest discover -s tools/tests - name: Check formatting and analyze workspace run: dart run melos run lint - - name: Require 100% coverage in changed packages - if: needs.changes.outputs.all == 'true' || needs.changes.outputs.packages != '' + + # One job per selected package; packages are independent, so they run in parallel. + test: + needs: changes + if: needs.changes.outputs.packages != '[]' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + package: ${{ fromJSON(needs.changes.outputs.packages) }} + name: test (${{ matrix.package }}) + steps: + - uses: actions/checkout@v7 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ env.FLUTTER_VERSION }} + cache: true + - uses: actions/setup-python@v7 + with: + python-version: "3.x" + - name: Resolve workspace dependencies + run: flutter pub get --enforce-lockfile + - name: Require 100% coverage + run: python3 tools/coverage.py --package "${{ matrix.package }}" + - id: artifact + if: always() env: - PACKAGES: ${{ needs.changes.outputs.packages }} + PACKAGE: ${{ matrix.package }} run: | - args=() - for package in $PACKAGES; do args+=(--package "$package"); done - python3 tools/coverage.py "${args[@]}" + name="${PACKAGE//\//-}" + echo "name=coverage-${name/#./root}" >> "$GITHUB_OUTPUT" - name: Save test logs and coverage reports if: always() uses: actions/upload-artifact@v7 with: - name: workspace-coverage + name: ${{ steps.artifact.outputs.name }} path: | coverage/ - packages/**/coverage/ - plugins/**/coverage/ - tools/**/coverage/ + ${{ matrix.package }}/coverage/ native-permissions: needs: changes - if: needs.changes.outputs.all == 'true' || contains(format(' {0} ', needs.changes.outputs.packages), ' plugins/contact_permission ') + if: contains(fromJSON(needs.changes.outputs.packages), 'plugins/contact_permission') runs-on: macos-latest timeout-minutes: 30 steps: diff --git a/docs/testing.md b/docs/testing.md index 6f7d966..cc460ae 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -24,7 +24,7 @@ python3 tools/coverage.py --package ns_utils python3 tools/coverage.py --package packages/timer_button/example ``` -CI tests only the packages changed since the base commit, plus their workspace dependents (`melos list --diff= --include-dependents`). The native permission job runs only when `contact_permission` is selected. Changes to shared inputs (root `pubspec.yaml`/`pubspec.lock`, `analysis_options.yaml`, root `test/`, `tools/coverage.py`, `tools/tests/`, root `tools/*.dart`, or the Dart workflow) run every package. Formatting and analysis always cover the whole workspace. +CI tests only the packages changed since the base commit, plus their workspace dependents (`melos list --diff= --include-dependents`), as a matrix with one parallel job per package. The native permission job runs only when `contact_permission` is selected. Changes to shared inputs (root `pubspec.yaml`/`pubspec.lock`, `analysis_options.yaml`, root `test/`, `tools/coverage.py`, `tools/tests/`, root `tools/*.dart`, or the Dart workflow) run every package. Formatting and analysis always cover the whole workspace. `--report-only` inspects existing reports and writes `summary-existing.json`; it does not establish a fresh passing result.