← Winnitude! Search  ·  Reader Mode (2723 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 128 LINKS

Update CI auto-formate by YashSuthar983 ยท Pull Request #6237 ยท RustPython/RustPython

Repository navigation

Update CI auto-formate - #6237


Merged
youknowone merged 4 commits into RustPython:main from YashSuthar983:chore/ci-autoformat Nov 10, 2025
Merged

Update CI auto-formate #6237 youknowone merged 4 commits into RustPython:main from YashSuthar983:chore/ci-autoformat

Conversation

YashSuthar983 commented Nov 4, 2025 · edited by coderabbitai
Bot
Loading



Copy link Copy Markdown
Contributor

After running all all test i have added a another which check the rust format and if its not correct it make a commit with
[skip ci] which tell github workflow to ignore this commit.

@youknowone now this should work. i tested again on my fork with different account for testing.
issue :#6204

Summary by CodeRabbit

  • Chores
    • Simplified linting: formatter removed so only the code-quality linter runs.
    • Added an automated formatting workflow that runs the formatter, commits formatting changes with [skip ci], and pushes updates back to the PR branch when needed.
    • Formatting job waits for CI to pass, respects [skip ci] on the head commit, and posts a PR comment when it applies changes.
Update CI auto-formate f4a5730
Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>

coderabbitai
Bot
commented Nov 4, 2025 · edited Loading



Copy link Copy Markdown
Contributor

Walkthrough

CI workflows updated: rustfmt removed from the lint job; a new PR-targeted auto-format workflow runs cargo fmt --all, commits/pushes formatting changes with [skip ci], and can post a PR comment. The auto-format run waits for checks and is gated to avoid CI loops.

Changes

Cohort / File(s) Summary
CI workflows (lint change + new auto-format)
/.github/workflows/ci.yaml, /.github/workflows/pr-auto-commit.yaml
Removed explicit rustfmt provisioning and the rustfmt execution step from the lint job (clippy remains). Added a new "PR Auto-format" workflow / auto_format_commit job that waits for checks, runs cargo fmt --all, detects diffs, commits with [skip ci], pushes to the PR branch, and optionally posts a PR comment. Includes concurrency controls, permission scoping, guarded execution for [skip ci], and configurable wait/retry settings.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant PR as Pull Request
  participant GH as GitHub Actions
  participant Core as Core Jobs (tests, clippy)
  participant AF as Auto-format Job
  participant Git as Git (commit/push)
  participant Comment as PR Commenter

  PR->>GH: open/update (pull_request_target)
  GH->>Core: run tests & clippy (rustfmt removed)
  Core-->>GH: status results
  GH->>AF: start auto-format (if head commit != "[skip ci]" and required checks passed)
  AF->>AF: setup toolchain (rustfmt), run `cargo fmt --all`
  alt formatting changes detected
    AF->>Git: commit with "[skip ci]" and push to PR branch
    Git-->>AF: push success
    AF->>Comment: post PR comment with auto-format details
  else no changes
    AF-->>GH: exit (already formatted)
  end
Loading

Estimated code review effort

๐ŸŽฏ 3 (Moderate) | โฑ๏ธ ~20 minutes

  • Inspect needs/concurrency groups for cycles and intended ordering.
  • Validate [skip ci] detection and edge cases (rebase/force-push).
  • Verify permissions and token/checkout usage for safe push and comment posting.

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

๐Ÿ‡ I hopped through CI with nimble feet,
I ran cargo fmt to make things neat,
Committed with "[skip ci]" to avoid a loop,
Pushed tidy lines and left a helpful scoop,
A rabbit's touch -- crisp, concise, and sweet.

Pre-merge checks and finishing touches

โŒ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check โ“ Inconclusive The title 'Update CI auto-formate' is vague and contains a typo ('auto-formate' instead of 'auto-format'), making it unclear about the specific changes involved. Revise the title to be more specific and correct the typo, such as 'Add auto-formatting CI workflow with cargo fmt' or 'Implement auto-format CI job for pull requests'.
โœ… Passed checks (2 passed)
Check name Status Explanation
Description Check โœ… Passed Check skipped - CodeRabbit's high-level summary is enabled.
Docstring Coverage โœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
โœจ Finishing touches ๐Ÿงช Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

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

YashSuthar983 closed this Nov 5, 2025 YashSuthar983 reopened this Nov 5, 2025

YashSuthar983 commented Nov 5, 2025



Copy link Copy Markdown
Contributor

Author

I don't know why this failing but I tested on my fork with the help of different account too and its working.

fanninpm reviewed Nov 5, 2025
View reviewed changes
Update .github/workflows/ci.yaml b6139b5
Co-authored-by: fanninpm <luxverdans@sbcglobal.net>
coderabbitai
Bot
reviewed Nov 5, 2025
View reviewed changes

coderabbitai
Bot
left a comment



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 .

Actionable comments posted: 1

๐Ÿงน Nitpick comments (2)
.github/workflows/ci.yaml (2)

452-462: Job dependency chain creates significant delay before formatting feedback.

The job depends on 7 prior jobs, which means formatting comments won't appear until all of those jobs finish. Consider whether this is intentional (to avoid conflicts) or whether an earlier checkpoint would be preferable.


481-493: Use git add -A to capture all changes (including untracked files).

Line 487 uses git add -u, which only stages modifications to already-tracked files. While cargo fmt typically doesn't create new files, using git add -A or git add . is more defensive:

-          git add -u
+          git add -A

Additionally, consider checking the git push exit code to ensure the push succeeded before setting formatted=true.

๐Ÿ“œ Review details

Configuration used : Path: .coderabbit.yml

Review profile : CHILL

Plan : Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between f4a5730 and b6139b5 .

๐Ÿ“’ Files selected for processing (1)
  • .github/workflows/ci.yaml (2 hunks)
๐Ÿงฐ Additional context used ๐Ÿง  Learnings (4) ๐Ÿ““ Common learnings
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 5932
File: .github/workflows/comment-commands.yml:18-24
Timestamp: 2025-07-10T10:08:43.330Z
Learning: In GitHub Actions workflows for the RustPython project, the maintainer ShaharNaveh prefers to keep workflows simple and doesn't mind if steps fail when the desired state is already achieved (e.g., user already assigned to an issue). Avoid suggesting complex error handling for edge cases they don't consider problematic.
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Format Rust code with the default rustfmt style (run `cargo fmt`)
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Run clippy and fix any warnings or lints introduced by your changes
๐Ÿ“š Learning: 2025-09-11T05:06:59.971Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Run clippy and fix any warnings or lints introduced by your changes

Applied to files:

  • .github/workflows/ci.yaml
๐Ÿ“š Learning: 2025-09-11T05:06:59.971Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Format Rust code with the default rustfmt style (run `cargo fmt`)

Applied to files:

  • .github/workflows/ci.yaml
๐Ÿ“š Learning: 2025-09-11T05:06:59.971Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to extra_tests/**/*.py : Use ruff to lint custom Python code

Applied to files:

  • .github/workflows/ci.yaml
โฐ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Check Rust code with clippy
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Run tests under miri
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Ensure compilation on various targets
  • GitHub Check: Check the WASM package and demo
๐Ÿ”‡ Additional comments (4)
.github/workflows/ci.yaml (4)

309-316: Lint job updates look good.

Removing rustfmt from the lint step and dedicating it to the new auto_format_commit job is a clean separation of concerns.


465-475: Checkout and Rust setup are correct.

Line 469 correctly uses ${{ github.event.pull_request.head.ref || github.ref_name }} to handle both PR and push events -- good alignment with the past suggestion from fanninpm.


476-480: Cargo fmt command is standard and correct.


495-501: PR comment logic is sound.

The conditional on line 496 correctly gates the comment to PR events, and the message is clear.

Comment thread .github/workflows/ci.yaml
pull-requests: write
name: Auto-format code
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}

fanninpm commented Nov 5, 2025



Copy link Copy Markdown
Contributor

@coderabbitai Why does CI fail?

coderabbitai
Bot
commented Nov 5, 2025



Copy link Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

๐Ÿงฉ Analysis chain

๐Ÿ Script executed:

#!/bin/bash
# Get the CI runs for this PR and their status
gh pr view 6237 --repo RustPython/RustPython --json statusCheckRollup | jq '.statusCheckRollup[] | {name: .name, status: .status, conclusion: .conclusion}'

# Get more detailed information about failed checks
gh pr checks 6237 --repo RustPython/RustPython

# Also get the workflow file to examine it
cat .github/workflows/ci.yaml | head -200

Length of output: 8609


๐Ÿ Script executed:

#!/bin/bash
# Get the logs from the failed Auto-format code job
gh run view 19111165461 --repo RustPython/RustPython --job 54610715495 --log

# Also let's look at the auto_format_commit job definition in the workflow file
cat .github/workflows/ci.yaml | grep -A 100 "auto_format_commit:"

Length of output: 23955


@fanninpm The CI is failing because of how the auto_format_commit job handles pull requests from forks. Here's the issue:

Root Cause

The error in the logs shows:

##[error]A branch or tag with the name 'chore/ci-autoformat' could not be found

This happens because:

  1. Branch location : The PR is from a fork (YashSuthar983/RustPython), so the branch chore/ci-autoformat exists in the fork repository, not in the main RustPython/RustPython repository.

  2. Checkout configuration : The workflow uses:

    ref: ${{ github.event.pull_request.head.ref || github.ref_name }}

    This evaluates to just the branch name chore/ci-autoformat, and the checkout action tries to find it in the main repository where it doesn't exist.

  3. Git fetch behavior : The fetch only retrieves branches from origin (the main repo), not from the fork:

    git fetch origin +refs/heads/*:refs/remotes/origin/*
    

Why It Worked on the Fork

When @YashSuthar983 tested this on their own fork, it worked because:

  • The branch exists in their repository
  • They have write permissions to their own repository
  • The checkout action can find and check out the branch

Additional Problem: Write Permissions

Even if the checkout issue were fixed, there's a security restriction: GitHub Actions from forked PRs don't have write permissions to the base repository by default . The workflow tries to push formatting changes back to the PR branch, which would fail for forked PRs.

Solutions

For this auto-format workflow to work properly with forked PRs, you have a few options:

  1. Use the default checkout (recommended for this use case) :

    - name: Checkout code
      uses: actions/checkout@v5
      with:
        fetch-depth: 0
        # Remove the ref parameter - let GitHub Actions handle it automatically
  2. Skip auto-format for forked PRs : Add a condition to only run on PRs from the main repository:

    if: ${{ !contains(github.event.head_commit.message, '[skip ci]') && github.event.pull_request.head.repo.full_name == github.repository }}
  3. Use pull_request_target (requires careful security consideration): This event type has write permissions but runs in the context of the base repository, which has security implications.

The simplest fix would be option #2 - only auto-format for PRs from branches in the main repository, not from forks.


๐Ÿง  Learnings used
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 5932
File: .github/workflows/comment-commands.yml:18-24
Timestamp: 2025-07-10T10:08:43.330Z
Learning: In GitHub Actions workflows for the RustPython project, the maintainer ShaharNaveh prefers to keep workflows simple and doesn't mind if steps fail when the desired state is already achieved (e.g., user already assigned to an issue). Avoid suggesting complex error handling for edge cases they don't consider problematic.

YashSuthar983 commented Nov 5, 2025



Copy link Copy Markdown
Contributor

Author

@fanninpm i am still confused as when i tested with my different account where i fork my fork then make a pr ,there it works .
maybe we can confirm this after merging this (this is not proffered but i am confused due to dual behaviour)

Revert suggested changes 3ed9216
Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
fanninpm reviewed Nov 5, 2025
View reviewed changes
Comment thread .github/workflows/ci.yaml
Outdated
uses: actions/checkout@v5
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
coderabbitai
Bot
reviewed Nov 5, 2025
View reviewed changes

coderabbitai
Bot
left a comment



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 .

Actionable comments posted: 1

โ™ป๏ธ Duplicate comments (1)
.github/workflows/ci.yaml (1)

459-459: CRITICAL: Condition fails on pull_request events.

Line 459 accesses github.event.head_commit.message, which is only available on push events. The workflow triggers on both push and pull_request (lines 2-5), so this condition is broken for PR events. For PRs, github.event.head_commit is null, causing contains(null, '[skip ci]') to behave unpredictably -- the job will likely run unconditionally.

This matches the root cause identified in the previous review: the workflow works on your fork (where you have permissions) but fails here because the condition doesn't distinguish event types. Per previous review recommendations, the simplest fix is to skip auto-format for fork PRs by checking the event type:

-    if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
+    if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}

This skips the job for fork PRs (where you don't have write permissions anyway) and checks the commit message only on push events where the context is available.

๐Ÿงน Nitpick comments (1)
.github/workflows/ci.yaml (1)

459-459: Align skip condition with other jobs.

Other jobs in this workflow use !contains(github.event.pull_request.labels.*.name, 'skip:ci') to determine whether to run (lines 111, 176, 237, etc.). The new job uses a different mechanism: commit message matching. For consistency and predictability, consider aligning the auto-format job to use the same label-based skip pattern already established throughout the workflow:

-    if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
+    if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}

This ensures that all jobs respond to the same skip:ci label, making the workflow behavior uniform and easier to reason about.

๐Ÿ“œ Review details

Configuration used : Path: .coderabbit.yml

Review profile : CHILL

Plan : Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between b6139b5 and 3ed9216 .

๐Ÿ“’ Files selected for processing (1)
  • .github/workflows/ci.yaml (2 hunks)
๐Ÿงฐ Additional context used ๐Ÿง  Learnings (5) ๐Ÿ““ Common learnings
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 5932
File: .github/workflows/comment-commands.yml:18-24
Timestamp: 2025-07-10T10:08:43.330Z
Learning: In GitHub Actions workflows for the RustPython project, the maintainer ShaharNaveh prefers to keep workflows simple and doesn't mind if steps fail when the desired state is already achieved (e.g., user already assigned to an issue). Avoid suggesting complex error handling for edge cases they don't consider problematic.
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Format Rust code with the default rustfmt style (run `cargo fmt`)
๐Ÿ“š Learning: 2025-09-11T05:06:59.971Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Run clippy and fix any warnings or lints introduced by your changes

Applied to files:

  • .github/workflows/ci.yaml
๐Ÿ“š Learning: 2025-09-11T05:06:59.971Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Format Rust code with the default rustfmt style (run `cargo fmt`)

Applied to files:

  • .github/workflows/ci.yaml
๐Ÿ“š Learning: 2025-07-10T10:08:43.330Z
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 5932
File: .github/workflows/comment-commands.yml:18-24
Timestamp: 2025-07-10T10:08:43.330Z
Learning: In GitHub Actions workflows for the RustPython project, the maintainer ShaharNaveh prefers to keep workflows simple and doesn't mind if steps fail when the desired state is already achieved (e.g., user already assigned to an issue). Avoid suggesting complex error handling for edge cases they don't consider problematic.

Applied to files:

  • .github/workflows/ci.yaml
๐Ÿ“š Learning: 2025-09-11T05:06:59.971Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to extra_tests/**/*.py : Use ruff to lint custom Python code

Applied to files:

  • .github/workflows/ci.yaml
โฐ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Run tests under miri
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Check Rust code with clippy
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Ensure compilation on various targets
๐Ÿ”‡ Additional comments (1)
.github/workflows/ci.yaml (1)

309-316: Lint job refactor looks good.

Removing rustfmt from the lint job and moving it to a separate auto-format job is a clean separation of concerns. The lint job retains clippy for static analysis, which is appropriate.

coderabbitai
Bot
reviewed Nov 8, 2025
View reviewed changes

coderabbitai
Bot
left a comment



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 .

Actionable comments posted: 2

๐Ÿ“œ Review details

Configuration used : Path: .coderabbit.yml

Review profile : CHILL

Plan : Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 3ed9216 and 40a778d .

๐Ÿ“’ Files selected for processing (1)
  • .github/workflows/pr-auto-commit.yaml (1 hunks)
๐Ÿงฐ Additional context used ๐Ÿง  Learnings (1) ๐Ÿ““ Common learnings
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 5932
File: .github/workflows/comment-commands.yml:18-24
Timestamp: 2025-07-10T10:08:43.330Z
Learning: In GitHub Actions workflows for the RustPython project, the maintainer ShaharNaveh prefers to keep workflows simple and doesn't mind if steps fail when the desired state is already achieved (e.g., user already assigned to an issue). Avoid suggesting complex error handling for edge cases they don't consider problematic.
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Format Rust code with the default rustfmt style (run `cargo fmt`)
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Run clippy and fix any warnings or lints introduced by your changes
๐Ÿช› actionlint (1.7.8) .github/workflows/pr-auto-commit.yaml

69-69: "github.event.pull_request.head.ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/reference/security/secure-use#good-practices-for-mitigating-script-injection-attacks for more details

(expression)

โฐ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Run tests under miri
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Check Rust code with clippy
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Ensure compilation on various targets
๐Ÿ”‡ Additional comments (2)
.github/workflows/pr-auto-commit.yaml (2)

78-92: Well-designed PR comment notification.

The PR comment step is appropriately gated to only run when formatting changes are detected, and the message clearly explains what happened and how to pull the latest changes. This is good UX.


37-46: ****

The poseidon/wait-for-status-checks action waits until all watched checks succeed (or are skipped) or one fails, meaning it validates success and exits with failure if any check fails. The workflow will not proceed past that step if checks don't pass. The echo at lines 45-46 merely confirms that the validation passed; no additional verification is needed.

Likely an incorrect or invalid review comment.

Comment thread .github/workflows/pr-auto-commit.yaml Comment on lines +16 to +26
auto_format:
if: |
!contains(github.event.pull_request.labels.*.name, 'skip:ci') &&
!contains(github.event.pull_request.head.sha, '[skip ci]')
permissions:
contents: write
pull-requests: write
checks: read
runs-on: ubuntu-latest
timeout-minutes: 60

Comment thread .github/workflows/pr-auto-commit.yaml Comment on lines +67 to +76
- name: Commit and push formatting changes
if: steps.check_changes.outputs.has_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

git add -u
git commit -m "Auto-format code [skip ci]"

git push origin HEAD:${{ github.event.pull_request.head.ref }}

YashSuthar983 commented Nov 8, 2025 · edited Loading



Copy link Copy Markdown
Contributor

Author

@fanninpm @youknowone now i have done diff approach here i used pull_request_target as this has more permissions then workflow_run .
now as i tested it working and auto-format only passes or give undesirable results when there is approval needed to run workflow(majorly fro first time contributors).

tested in pr

Added a seprate auto format workflow 012693f
Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
YashSuthar983 force-pushed the chore/ci-autoformat branch from 40a778d to 012693f
Compare
November 8, 2025 18:25 coderabbitai
Bot
reviewed Nov 8, 2025
View reviewed changes

coderabbitai
Bot
left a comment



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 .

Actionable comments posted: 0

โ™ป๏ธ Duplicate comments (2)
.github/workflows/pr-auto-commit.yaml (2)

16-19: โš ๏ธ Critical: Add fork guard to prevent workflow failure on forked PRs.

The job condition lacks a check to ensure the PR originates from the base repository. When this workflow runs on PRs from forked repositories, GitHub Actions in the base repo cannot push to the fork's branch, causing the workflow to fail. This is why the workflow succeeds in the author's fork but fails in the main repository.

Add a guard to skip auto-format for forked PRs:

  auto_format:
    if: |
      !contains(github.event.pull_request.labels.*.name, 'skip:ci') &&
      !contains(github.event.pull_request.head.sha, '[skip ci]') &&
+     github.event.pull_request.head.repo.full_name == github.repository

This ensures the job only runs for PRs opened against the main repository, not forked PRs.


67-76: โš ๏ธ Major: Mitigate script injection risk by passing ref through environment variable.

Line 76 directly interpolates github.event.pull_request.head.ref into the inline shell script. An untrusted PR ref could be crafted to inject arbitrary shell commands. Per GitHub's security guidance, pass the ref through an environment variable instead:

  - name: Commit and push formatting changes
    if: steps.check_changes.outputs.has_changes == 'true'
+   env:
+     HEAD_REF: ${{ github.event.pull_request.head.ref }}
    run: |
      git config user.name "github-actions[bot]"
      git config user.email "github-actions[bot]@users.noreply.github.com"
      
      git add -u
      git commit -m "Auto-format code [skip ci]"
      
-     git push origin HEAD:${{ github.event.pull_request.head.ref }}
+     git push origin HEAD:"$HEAD_REF"
๐Ÿงน Nitpick comments (1)
.github/workflows/pr-auto-commit.yaml (1)

78-95: Minor: Consistent script variable handling in PR comment message.

Line 94 also interpolates ${{ github.event.pull_request.head.ref }} directly. While this is in a message/documentation context (lower risk than the git push command), apply the same mitigation for consistency and to establish a pattern:

  - name: Comment on PR
    if: steps.check_changes.outputs.has_changes == 'true'
+   env:
+     HEAD_REF: ${{ github.event.pull_request.head.ref }}
    uses: marocchino/sticky-pull-request-comment@v2
    with:
      number: ${{ github.event.pull_request.number }}
      message: |
        **Code has been automatically formatted**
        
        The code in this PR has been formatted using `cargo fmt`.
        The changes have been committed with `[skip ci]` to avoid triggering another CI run.
        
        **Triggered by commit:** `${{ github.event.pull_request.head.sha }}`  
        **Last formatted:** ${{ github.event.pull_request.updated_at }}
        
        You may need to pull the latest changes before pushing again:
        ```bash
-       git pull origin ${{ github.event.pull_request.head.ref }}
+       git pull origin "$HEAD_REF"
        ```
๐Ÿ“œ Review details

Configuration used : Path: .coderabbit.yml

Review profile : CHILL

Plan : Pro

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 40a778d and 012693f .

๐Ÿ“’ Files selected for processing (1)
  • .github/workflows/pr-auto-commit.yaml (1 hunks)
๐Ÿงฐ Additional context used ๐Ÿง  Learnings (2) ๐Ÿ““ Common learnings
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 5932
File: .github/workflows/comment-commands.yml:18-24
Timestamp: 2025-07-10T10:08:43.330Z
Learning: In GitHub Actions workflows for the RustPython project, the maintainer ShaharNaveh prefers to keep workflows simple and doesn't mind if steps fail when the desired state is already achieved (e.g., user already assigned to an issue). Avoid suggesting complex error handling for edge cases they don't consider problematic.
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Format Rust code with the default rustfmt style (run `cargo fmt`)
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-11T05:06:59.971Z
Learning: Applies to **/*.rs : Run clippy and fix any warnings or lints introduced by your changes
๐Ÿ“š Learning: 2025-07-10T10:08:43.330Z
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 5932
File: .github/workflows/comment-commands.yml:18-24
Timestamp: 2025-07-10T10:08:43.330Z
Learning: In GitHub Actions workflows for the RustPython project, the maintainer ShaharNaveh prefers to keep workflows simple and doesn't mind if steps fail when the desired state is already achieved (e.g., user already assigned to an issue). Avoid suggesting complex error handling for edge cases they don't consider problematic.

Applied to files:

  • .github/workflows/pr-auto-commit.yaml
๐Ÿช› actionlint (1.7.8) .github/workflows/pr-auto-commit.yaml

69-69: "github.event.pull_request.head.ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/reference/security/secure-use#good-practices-for-mitigating-script-injection-attacks for more details

(expression)

โฐ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Check Rust code with clippy
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Ensure compilation on various targets

youknowone commented Nov 10, 2025



Copy link Copy Markdown
Member

I'm a bit concerned about the formatting failure, but let's give it another try.

youknowone merged commit 2d46172 into RustPython : main Nov 10, 2025

youknowone commented Nov 10, 2025



Copy link Copy Markdown
Member

Great, it looks working well!

https://github.com/RustPython/RustPython/actions/runs/19235980885/job/54985900338?pr=6234

youknowone commented Nov 10, 2025



Copy link Copy Markdown
Member

Thank you so much! ๐Ÿ‘

ShaharNaveh mentioned this pull request Nov 10, 2025 Move __doc__ crate to crates/doc #6234 Merged

youknowone commented Nov 10, 2025



Copy link Copy Markdown
Member

okay, not good in this case: https://github.com/RustPython/RustPython/actions/runs/19236037205/job/54989070706?pr=6234

YashSuthar983 commented Nov 10, 2025 · edited Loading



Copy link Copy Markdown
Contributor

Author

@youknowone i guess its failing because fork using old auto-commit job,
See this test pr #6247 and #6248 .

This was referenced Nov 10, 2025 remove old auto-formte implimentaion from ci.yaml #6250 Closed removed old auto-format implimentaion from ci.yaml #6251 Merged Native triggers for workflow dependency #6253 Closed coderabbitai
Bot
mentioned this pull request Mar 7, 2026 replace auto commit to format suggestion #7375 Merged coderabbitai
Bot
mentioned this pull request Mar 12, 2026 Fix pr-format CI to fail on formatting changes #7411 Merged Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment

Labels

None yet

3 participants