-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Only run cargo check when rust code is changed
#7572
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,42 @@ env: | |||||||||||||||||||||||||
| CARGO_TERM_COLOR: always | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||
| determine_changes: | ||||||||||||||||||||||||||
| name: Determine changes | ||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||
| outputs: | ||||||||||||||||||||||||||
| # Flag that is raised when any rust code is changed. | ||||||||||||||||||||||||||
| rust_code: ${{ steps.check_rust_code.outputs.changed }} | ||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||
| fetch-depth: 0 | ||||||||||||||||||||||||||
| persist-credentials: false | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - name: Determine merge base | ||||||||||||||||||||||||||
| id: merge_base | ||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||
| sha=$(git merge-base HEAD "origin/${BASE_REF}") | ||||||||||||||||||||||||||
| echo "sha=${sha}" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||
| BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }} | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - name: Check if there was any code related change | ||||||||||||||||||||||||||
| id: check_rust_code | ||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||
| if git diff --quiet "${MERGE_BASE}...HEAD" -- \ | ||||||||||||||||||||||||||
| ':!Lib/**' \ | ||||||||||||||||||||||||||
| ':!scripts/**' \ | ||||||||||||||||||||||||||
| ':!extra_tests/**' \ | ||||||||||||||||||||||||||
| ':.github/workflows/ci.yaml' \ | ||||||||||||||||||||||||||
| ; then | ||||||||||||||||||||||||||
|
Comment on lines
+60
to
+65
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Current expression (with typo) matches:"
git ls-files -- ':!Lib/**' ':!scripts/**' ':!extra_tests/**' ':.github/workflows/ci.yaml' | sed -n '1,20p'
echo
echo "Fixed expression matches:"
git ls-files -- ':!Lib/**' ':!scripts/**' ':!extra_tests/**' ':!.github/workflows/ci.yaml' | sed -n '1,20p'
echo
echo "Expected: first output is narrowly scoped; second output includes repo files excluding the specified paths."Repository: RustPython/RustPython Length of output: 774 🏁 Script executed: cat -n .github/workflows/ci.yaml | head -100Repository: RustPython/RustPython Length of output: 4096 🏁 Script executed: grep -n "rust_code" .github/workflows/ci.yamlRepository: RustPython/RustPython Length of output: 222 🏁 Script executed: sed -n '150,165p' .github/workflows/ci.yamlRepository: RustPython/RustPython Length of output: 530 Fix pathspec typo at line 64 (
One-line fix- ':.github/workflows/ci.yaml' \
+ ':!.github/workflows/ci.yaml' \📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ShaharNaveh I think you may have missed this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||
| echo "changed=false" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||
| echo "changed=true" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||
| MERGE_BASE: ${{ steps.merge_base.outputs.sha }} | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| rust_tests: | ||||||||||||||||||||||||||
| if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }} | ||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||
|
|
@@ -111,9 +147,13 @@ jobs: | |||||||||||||||||||||||||
| if: runner.os == 'Linux' | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| cargo_check: | ||||||||||||||||||||||||||
| if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }} | ||||||||||||||||||||||||||
| name: cargo check | ||||||||||||||||||||||||||
| runs-on: ${{ matrix.os }} | ||||||||||||||||||||||||||
| needs: | ||||||||||||||||||||||||||
| - determine_changes | ||||||||||||||||||||||||||
| if: | | ||||||||||||||||||||||||||
| !contains(github.event.pull_request.labels.*.name, 'skip:ci') && | ||||||||||||||||||||||||||
| needs.determine_changes.outputs.rust_code == 'true' | ||||||||||||||||||||||||||
| strategy: | ||||||||||||||||||||||||||
| matrix: | ||||||||||||||||||||||||||
| include: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
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.
🧩 Analysis chain
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 285
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1011
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 1595
🏁 Script executed:
Repository: RustPython/RustPython
Length of output: 377
Fix merge-base logic for push events and correct pathspec in diff filter; currently
cargo_checknever runs and change detection is broken.Two issues prevent the change detection from working:
Push to main always skips
cargo_check: At line 52,git merge-base HEAD "origin/${BASE_REF}"resolves toHEADon push to main, making the diff empty andrust_codealways false. Usegithub.event.beforefor push events instead.Pathspec at line 64 is incorrect:
':.github/workflows/ci.yaml'includes only the workflow file (inverted logic). Should be':!.github/workflows/ci.yaml'to exclude it like the other directories.Proposed fixes
For the merge-base step (lines 49-55):
- name: Determine merge base id: merge_base run: | - sha=$(git merge-base HEAD "origin/${BASE_REF}") + if [ "${GITHUB_EVENT_NAME}" = "push" ] && [ -n "${BEFORE_SHA}" ]; then + sha="${BEFORE_SHA}" + else + sha=$(git merge-base HEAD "origin/${BASE_REF}") + fi echo "sha=${sha}" >> "$GITHUB_OUTPUT" env: BASE_REF: ${{ github.event.pull_request.base.ref || 'main' }} + BEFORE_SHA: ${{ github.event.before }}For the pathspec (line 64):
if git diff --quiet "${MERGE_BASE}...HEAD" -- \ ':!Lib/**' \ ':!scripts/**' \ ':!extra_tests/**' \ - ':.github/workflows/ci.yaml' \ + ':!.github/workflows/ci.yaml' \📝 Committable suggestion
🤖 Prompt for AI Agents