-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Implement fast bazel target lookup with index caching #16974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a hybrid approach to determining which Bazel test targets to run in CI by introducing an index-based caching mechanism. The system builds a comprehensive index of test targets and their dependencies during scheduled runs, then uses this cached index for faster lookups during regular PR and push events.
Changes:
- Replaces shell-based target discovery with Ruby Rake tasks for better flexibility and performance
- Implements index caching via GitHub Actions cache to enable fast target lookups
- Simplifies CI workflow conditionals by consolidating binding-specific logic
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/github-actions/check-bazel-targets.sh | Deleted shell script that performed slow Bazel queries, replaced by Rake tasks |
| Rakefile | Added two new Rake tasks (bazel:build_test_index and bazel:affected_targets) with supporting helper functions for index creation and target lookup |
| rb/.rubocop.yml | Excluded Rakefile from Lint/RedundantRequireStatement check for the new 'set' requirement |
| .github/workflows/ci.yml | Added build-index job for scheduled runs, updated check job to use cached index, simplified per-binding conditionals |
| .github/workflows/ci-build-index.yml | New workflow for building and caching the test target index |
| .github/workflows/bazel.yml | Added cache-name input parameter to support restoring cached index files |
9a825c6 to
9ba59a8
Compare
|
I committed 0850cd0 which does the indexing part of this. Once a scheduled CI job has run building the index without issues, I'll merge the rest of this. |
6a70092 to
5955cb3
Compare
|
I'm putting in draft until #16985 merges |
8e89e2a to
f01506a
Compare
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||
|
It should index on linux now. |
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 11 comments.
Now that trunk has the fix for macOS-only archive rules, the index can be built on Linux which is faster and cheaper. Co-Authored-By: Claude Opus 4.5 <[email protected]>
f5b6646 to
aff0568
Compare
User description
I've tried several times to improve how we determine which targets to run tests against.
The options are all either inaccurate (just run everything) or slow (so slow they were timing out).
This is the hybrid approach. Do the slow thing 2x a day when scheduled CI runs, and the fast thing every other time. Should be good enough.
The pre-release PR found 2437 matching targets, this PR finds the correct 570.
💥 What does this PR do?
bazel:build_test_indexto index test targets based on affected BUILD packagesbazel:affected_targetsto provide a list of test targets that applyEdge Cases:
#find_bazel_packagelocates the package and runs tests for that package#find_bazel_packagelocates the package and runs tests for that package🔧 Implementation Notes
I've spent way too long on this. I tried the tools, I tried various shortcuts, no good way to get accuracy with any speed.
I went back and forth on shell vs python vs rake, and Rake gives me the most flexibility, and lets us easily do this from local or on CI
💡 Additional Considerations
JavaScript will need to be added later
Rust is ignored in the indexing because we aren't toggling rust tests from this
This doesn't actually use the targets in the ci.yml yet, so we're still just seeing if there are any and running everything.
Actually limiting things is next
🔄 Types of changes
PR Type
Enhancement, Tests
Description
Replace slow shell script with fast Rake-based Bazel target lookup using index caching
Add
bazel:build_test_indextask to generate test target index from BUILD packagesAdd
bazel:affected_targetstask to find affected targets using index or fallbackSimplify CI conditionals by splitting target output into per-binding flags
Switch index generation from macOS to Linux for faster, cheaper builds
Support workflow dispatch to rebuild index and run all tests
Diagram Walkthrough
flowchart LR A["Changed Files"] --> B["affected_targets Task"] B --> C{"Index Exists?"} C -->|Yes| D["Query Index"] C -->|No| E["Directory Fallback"] D --> F["Test Targets"] E --> F G["build_test_index Task"] --> H["Generate Index from BUILD Packages"] H --> I["Cache Index"] I --> DFile Walkthrough
check-bazel-targets.sh
Remove slow shell-based target lookup scriptscripts/github-actions/check-bazel-targets.sh
bazel.yml
Add cache restore support for index files.github/workflows/bazel.yml
cache-nameinput parameter for cache restore functionalityci-build-index.yml
Switch index generation to Linux platform.github/workflows/ci-build-index.yml
ci.yml
Refactor CI workflow to use Rake tasks and per-binding flags.github/workflows/ci.yml
combined targets
expressions to simple flag checks
Rakefile
Add Rake tasks for fast Bazel target lookup with indexRakefile
checks)
bazel:affected_targetstask to find test targets affected byfile changes
bazel:build_test_indextask to generate index from BUILDpackages
find_bazel_package,affected_targets_with_index,targets_from_lookup,query_package_dep,targets_from_tests,affected_targets_fallbackpackages
dependencies