refactor(ci): scope PR jobs to packages changed by the PR#2109
refactor(ci): scope PR jobs to packages changed by the PR#2109xsahil03x wants to merge 2 commits into
Conversation
b119ace to
5d047aa
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2109 +/- ##
=======================================
Coverage 60.57% 60.57%
=======================================
Files 383 383
Lines 23927 23927
=======================================
Hits 14493 14493
Misses 9434 9434 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5d047aa to
a68cdfa
Compare
Adds `analyze:changes`, `format:changes`, `test:changes`, and `lint:pub:changes` melos scripts that run only on packages a PR touches (plus their transitive dependents). The diff range is `HEAD~1...HEAD`, which works for both PR events (HEAD~1 is the base-branch tip on GitHub's merge ref, regardless of which branch the PR targets) and push events (HEAD~1 is the previous tip). `test:changes` delegates to `.github/workflows/scripts/test-package.sh` because melos applies packageFilters BEFORE `--include-dependents`, so examples (no test/ directory, but path-depend on every changed package) get pulled back into the set via transitive deps and can't be filtered out by `dirExists`. The wrapper skips them per-package after the affected set is computed, with explicit exit codes so real test failures propagate. Coverage checks gain `hashFiles()` guards so they skip cleanly when their package wasn't touched on this PR. Codecov upload moves to last so we never push coverage that failed local thresholds. The legacy `ACTIONS_ALLOW_UNSECURE_COMMANDS` env var is removed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
a68cdfa to
316b915
Compare
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…cles - Remove `metrics` + `analyze:all` scripts. dart_code_metrics's OSS version was discontinued in 2024 (the maintainer pivoted to commercial DCM); the script wasn't actually installed anywhere, so the command would have failed if anyone ran it. - Switch `generate:dart` and `generate:flutter` to `dart run build_runner`. `flutter pub run` has been deprecated since Flutter 3.7 (Feb 2023); `dart run` works for both Dart and Flutter packages and skips the Flutter binary warmup. Also moved both scripts to melos's `exec:` shorthand — `packageFilters` is now a first-class sibling key, no more `--depends-on=... --no-flutter` flag parsing in a quoted string. - Add `lint:cycles` script (wraps `melos list --cycles`) and run it before bootstrap in the analyze job. Fails fast if anyone introduces a circular dep — ~1s to run, saves the full bootstrap cost on a doomed PR. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the previous diff-aware-CI attempt on this branch with a version that addresses the bugs we found in the original — silent test failures from the bash
&&/||trap, and example packages leaking back into the affected set via melos's dependent expansion.What changes
Four new diff-aware melos scripts that scope each job to only the packages a PR touches (plus their transitive dependents):
analyze:changes—dart analyzeon changed packages and their dependents (includes examples; analyzing them catches API drift in the sample code)format:changes—dart format --set-exit-if-changedon the same settest:changes—flutter test --no-pub --coverage, with a wrapper script that skips packages without atest/directorylint:pub:changes—flutter pub publish --dry-runon publishable changed packagesThe workflow's
analyze/format/testjobs now call the:changesvariants directly. Push events to master use the same scripts —HEAD~1resolves to the previous tip there, scoping to the merge commit's changes.Why
HEAD~1...HEAD(no env var, nogithub.base_ref)GitHub Actions's default checkout for
pull_requestevents checks out an auto-generated merge commit atrefs/pull/N/merge. On that commit:HEAD^1(first parent) = base branch tip —master,v10.0.0,feat/design-refresh, whatever the PR targetsHEAD^2(second parent) = PR head tipSo
HEAD~1...HEADis always exactly the PR's effective diff, regardless of which branch it targets, with zero workflow plumbing. On push events,HEAD~1is the previous tip — same diff shape.Verified empirically:
Pre-existing files (
a,b) correctly excluded; only the feature branch's added files appear.Why
test:changesneeds a wrapper scriptThe melos filter pipeline (
packages/melos/lib/src/package.dart:800) runs in this order:applyIgnore,applyDirExists,applyFileExistsfilterPrivatePackages,applyScope,applyCategoriesapplyDependsOn/applyNoDependsOnfilterNullSafe,filterPublishedPackagesapplyDiffapplyIncludeDependentsOrDependencies← runs LAST, walks_packageMap(the unfiltered workspace)So
--ignore=\"*example*\"andpackageFilters: { dirExists: test }correctly filter examples out of the initial set — but--include-dependentsthen pulls them straight back in from the full workspace. Confirmed locally: a single change tostream_chatwith--include-dependentsselects 11 packages, 5 of them*_example.We can't drop
--include-dependents(we need to test that a change tostream_chatdoesn't break tests instream_chat_flutter), and we don't want to remove examples from the workspace (they need to participate in analyze/format). So the skip decision happens per-package, after melos has computed the affected set:set -eplus explicitexecensures real test failures propagate — the original `[ -d test ] && flutter test ... || echo skip` pattern would silently swallow non-zero exits fromflutter test(classic bash&&/||precedence bug).lint:pub:changesdoesn't need a wrapper becausepub publish --dry-runonly validates this package's own pubspec/files/metadata — never reads the parent's code — so we drop--include-dependentsentirely and--no-privatefilters examples cleanly.Other workflow cleanups
if: hashFiles('packages/X/coverage/lcov.info') != ''guards so they skip cleanly when their package wasn't touched (no "file not found" errors)ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'env var (security smell, deprecated)gatejob, fastlane Android/iOSbuildmatrix, SQLite3 install for persistence tests,validate-formatting.shLocal usage
The full
analyze/format/test:all/lint:pubscripts are kept untouched for the local "check everything" use case.Caveats worth knowing
actions/checkoutdefaults — if anyone later setsref: \${{ github.event.pull_request.head.sha }}, theHEAD~1trick stops resolving to the base branch.fetch-depth: 0(already set everywhere in this workflow) soHEAD~1resolves on the runner.Summary by CodeRabbit