ci: only commit gRPC cache updates on pull requests#3193
ci: only commit gRPC cache updates on pull requests#3193QuantumExplorer merged 8 commits intov3.1-devfrom
Conversation
The cache commit step was triggering on push to protected branches (v*-dev, master), which fails because branch protection requires changes via PR. Now only commits on pull_request events from the same repo, checking out the PR head branch first. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdded six implemented gRPC query entries to the query cache and updated its timestamp. Adjusted the CI workflow to set checkout Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
actions/checkout defaults to the merge ref on PRs (detached HEAD), so git checkout of the branch name fails. Use ref: github.head_ref to check out the actual branch, falling back to github.ref for push/dispatch events. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add safety check comparing current branch against expected github.head_ref before git push. Prevents accidental pushes to wrong branch if checkout didn't work as expected. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ gRPC Query Coverage Report |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/tests-rs-sdk-grpc-coverage.yml:
- Around line 66-71: The workflow currently interpolates the user-controlled
github.head_ref directly into the shell script; instead set an environment
variable (e.g., EXPECTED) from the workflow YAML using EXPECTED: ${{
github.head_ref }} and then reference that safe env var in the script (use
BRANCH=$(git branch --show-current) and compare to "$EXPECTED"). Update the step
to export/declare EXPECTED in the job or step env and remove any direct inline
interpolation of github.head_ref inside the shell commands so the script only
reads the value from the environment.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a65a1d08-d3da-4207-a287-ce4a962be9ad
📒 Files selected for processing (2)
.github/grpc-queries-cache.json.github/workflows/tests-rs-sdk-grpc-coverage.yml
Move user-controlled github.head_ref from direct ${{ }} interpolation
to a step-level environment variable, preventing potential shell
injection via crafted branch names.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
thepastaclaw
left a comment
There was a problem hiding this comment.
Reviewed — this looks good. Clean fix for a real problem.
What's here:
- Cache commit condition switches from
push(can't write to protected branches) →pull_request(can push to PR head branch). Correct fix. ref: ${{ github.head_ref || github.ref }}added to checkout — ensures we're on the actual branch, not detached HEAD. Needed for the git push.- Branch safety guard compares
git branch --show-currentagainst expected — good belt-and-suspenders. github.head_refpassed viaenv:block, not inline interpolation — addresses the script injection vector that CodeRabbit flagged (already fixed in this revision).- Same-repo guard (
head.repo.full_name == github.repository) prevents pushes on fork PRs — matches existing pattern in the Comment PR step.
Cache JSON adds 6 new address-related queries. Looks like it reflects current proto state.
One minor note: the push trigger is still present in on: — meaning the coverage check still runs on push to protected branches (just the commit step is skipped). That seems intentional since you still want the coverage report artifact on push events. 👍
Issue being fixed or feature implemented
The "Check rs-sdk gRPC coverage" workflow tries to commit cache updates directly to protected branches (
v*-dev,master) on push events, which fails with:See: https://github.com/dashpay/platform/actions/runs/22679875743/job/65747025659
User Story
Imagine you are a developer merging a PR that touches gRPC protos. The merge triggers a push event on
v3.1-dev, which runs the gRPC coverage check. The cache update step tries to push directly to the protected branch and fails — making the CI red for no good reason.What was done?
Changed the "Commit cache updates" step condition from:
github.event_name == 'push'(can't push to protected branches)To:
github.event_name == 'pull_request'(can push to PR head branch)Also added
git checkout "${{ github.head_ref }}"since PR checkouts are in detached HEAD state.The same guard (
github.event.pull_request.head.repo.full_name == github.repository) is used as the existing "Comment PR" step, ensuring we only push to same-repo PRs (not forks).How Has This Been Tested?
Breaking Changes
None
Checklist:
🤖 Co-authored by Claudius the Magnificent AI Agent
Summary by CodeRabbit
New Features
Chores