Skip to content

Only run cargo check when rust code is changed#7760

Merged
youknowone merged 6 commits into
RustPython:mainfrom
ShaharNaveh:cargo-check-when-needed
May 2, 2026
Merged

Only run cargo check when rust code is changed#7760
youknowone merged 6 commits into
RustPython:mainfrom
ShaharNaveh:cargo-check-when-needed

Conversation

@ShaharNaveh
Copy link
Copy Markdown
Contributor

@ShaharNaveh ShaharNaveh commented May 2, 2026

Summary by CodeRabbit

  • Chores
    • CI now detects whether Rust-related or workflow changes are present and runs Rust checks only when needed, reducing unnecessary runs.
    • A new detection step ensures the skip label is respected so Rust checks can be skipped when requested.
    • Rust checks still run unconditionally on the main branch to maintain baseline validation and prevent regressions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: f20c96cd-300f-4f39-a116-a9c8d40379e9

📥 Commits

Reviewing files that changed from the base of the PR and between fbc6582 and 1c7f1bc.

📒 Files selected for processing (1)
  • .github/workflows/ci.yaml

📝 Walkthrough

Walkthrough

The CI workflow adds a determine_changes job that diffs merge-base→HEAD for Rust-relevant paths (and the workflow file) and emits rust_code. cargo_check now depends on that job and runs only when Rust changes are detected (and no skip:ci label), or always on refs/heads/main.

Changes

Conditional Rust Code Detection

Layer / File(s) Summary
Change Detection
.github/workflows/ci.yaml (.github/workflows/ci.yaml lines ~39–77)
Adds determine_changes job: checks out full history, computes merge-base vs `origin/${{ github.event.pull_request.base.ref
Execution Gating / Wiring
.github/workflows/ci.yaml (.github/workflows/ci.yaml lines ~161–170)
Adds needs: [determine_changes] to cargo_check and changes its condition to run only when determine_changes.outputs.rust_code == 'true' and PR labels do not contain skip:ci, or unconditionally when github.ref == 'refs/heads/main'.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • youknowone
  • fanninpm

Poem

🐇 I sniff the merge-base, tail a-flutter,
Cargo files I scan with a gentle mutter.
If Rust is quiet, I hush the run—
But on main I leap, the checks are done.
Hop, hop, CI trimmed—🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: conditionally running cargo check only when Rust code is modified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@ShaharNaveh
Copy link
Copy Markdown
Contributor Author

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 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/ci.yaml:
- Around line 62-72: The git diff pathspecs in the conditional that checks
"${MERGE_BASE}...HEAD" do not include rust-toolchain.toml or .cargo/config.toml,
so changes to toolchain pinning or cargo config won't set "changed=true"; update
the pathspec list inside that if-block (the block that echoes
"changed=true"/"changed=false") to also include 'rust-toolchain.toml' and
'.cargo/config.toml' so the check in the ci workflow picks up edits to those
files.
- Around line 164-168: The current job if-expression is inadvertently wrapped by
GitHub Actions' default success() which can make cargo_check skip on
refs/heads/main if determine_changes fails; update the condition so it includes
an explicit status-check only on the main-branch arm (e.g., change the main
clause to "github.ref == 'refs/heads/main' && always()") so the presence of a
status function prevents the implicit success() wrapping while leaving the
existing determine_changes-based arm unchanged; target the if in the cargo_check
job and modify the expression that references
needs.determine_changes.outputs.rust_code and github.ref.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 2002e931-2cb2-48cb-88b0-8f7e305ff6b0

📥 Commits

Reviewing files that changed from the base of the PR and between 1f23cc3 and fbc6582.

📒 Files selected for processing (1)
  • .github/workflows/ci.yaml

Comment thread .github/workflows/ci.yaml
Comment thread .github/workflows/ci.yaml
Comment on lines +164 to +168
if: |
(
!contains(github.event.pull_request.labels.*.name, 'skip:ci') &&
needs.determine_changes.outputs.rust_code == 'true'
) || github.ref == 'refs/heads/main'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

cargo_check may be silently skipped on main if determine_changes fails

GitHub Actions implicitly wraps any job if expression with success() when no explicit status-check function is present. "A default status check of success() is applied unless you include one of these functions." This means the effective condition is:

success() && ( (…skip:ci check… && rust_code == 'true') || github.ref == 'refs/heads/main' )

If determine_changes fails (e.g., git merge-base cannot resolve origin/${BASE_REF}), success() evaluates to false and the entire expression short-circuits — so cargo_check is silently skipped even on refs/heads/main, defeating the intent of the unconditional escape hatch. The fix is to guard only the main branch arm with an explicit status-check:

🛠️ Proposed fix
-    if: |
-      (
-        !contains(github.event.pull_request.labels.*.name, 'skip:ci') &&
-        needs.determine_changes.outputs.rust_code == 'true'
-      ) || github.ref == 'refs/heads/main'
+    if: |
+      (
+        needs.determine_changes.result == 'success' &&
+        !contains(github.event.pull_request.labels.*.name, 'skip:ci') &&
+        needs.determine_changes.outputs.rust_code == 'true'
+      ) || (
+        !failure() && !cancelled() &&
+        github.ref == 'refs/heads/main'
+      )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/ci.yaml around lines 164 - 168, The current job
if-expression is inadvertently wrapped by GitHub Actions' default success()
which can make cargo_check skip on refs/heads/main if determine_changes fails;
update the condition so it includes an explicit status-check only on the
main-branch arm (e.g., change the main clause to "github.ref ==
'refs/heads/main' && always()") so the presence of a status function prevents
the implicit success() wrapping while leaving the existing
determine_changes-based arm unchanged; target the if in the cargo_check job and
modify the expression that references needs.determine_changes.outputs.rust_code
and github.ref.

@youknowone youknowone merged commit ac3e067 into RustPython:main May 2, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants