From f4a5730226ca6fd34fa7fd06940b261c60cbddd4 Mon Sep 17 00:00:00 2001 From: Yash Suthar Date: Wed, 5 Nov 2025 01:03:36 +0530 Subject: [PATCH 1/5] Update CI auto-formate Signed-off-by: Yash Suthar --- .github/workflows/ci.yaml | 58 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 977f27f376..c61d46c4da 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -307,15 +307,13 @@ jobs: run: python -I whats_left.py lint: - name: Check Rust code with rustfmt and clippy + name: Check Rust code with clippy runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: dtolnay/rust-toolchain@stable with: - components: rustfmt, clippy - - name: run rustfmt - run: cargo fmt --check + components: clippy - name: run clippy on wasm run: cargo clippy --manifest-path=wasm/lib/Cargo.toml -- -Dwarnings - uses: actions/setup-python@v6 @@ -450,3 +448,55 @@ jobs: run: wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/extra_tests/snippets/stdlib_random.py - name: run cpython unittest run: wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/Lib/test/test_int.py + + auto_format_commit: + needs: [rust_tests, exotic_targets, snippets_cpython, lint, miri, wasm, wasm-wasi] + permissions: + contents: write + pull-requests: write + name: Auto-format code + runs-on: ubuntu-latest + if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }} + concurrency: + group: fmt-${{ github.ref }} + cancel-in-progress: true + + steps: + - name: Checkout code + uses: actions/checkout@v5 + with: + fetch-depth: 0 + ref: ${{ github.head_ref || github.ref_name }} + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: Run cargo fmt + run: | + echo "Running cargo fmt --all" + cargo fmt --all + + - name: Commit and push if changes + id: commit + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + if [ -n "$(git status --porcelain)" ]; then + git add -u + git commit -m "Auto-format code [skip ci]" + git push + echo "formatted=true" >> $GITHUB_OUTPUT + else + echo "formatted=false" >> $GITHUB_OUTPUT + fi + + - name: Comment on PR if formatting was applied + if: steps.commit.outputs.formatted == 'true' && github.event_name == 'pull_request' + uses: marocchino/sticky-pull-request-comment@v2 + with: + message: | + Code has been automatically formatted. + No action needed. + the changes were committed with `[skip ci]`. From b6139b5c87a6f4b347898216550e28932889ea88 Mon Sep 17 00:00:00 2001 From: Yash Suthar Date: Wed, 5 Nov 2025 23:16:29 +0530 Subject: [PATCH 2/5] Update .github/workflows/ci.yaml Co-authored-by: fanninpm --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c61d46c4da..7b374fb233 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -466,7 +466,7 @@ jobs: uses: actions/checkout@v5 with: fetch-depth: 0 - ref: ${{ github.head_ref || github.ref_name }} + ref: ${{ github.event.pull_request.head.ref || github.ref_name }} - name: Setup Rust uses: dtolnay/rust-toolchain@stable From 3ed92168eb756fd20b6f33e215fac13441d58667 Mon Sep 17 00:00:00 2001 From: Yash Suthar Date: Wed, 5 Nov 2025 23:58:55 +0530 Subject: [PATCH 3/5] Revert suggested changes Signed-off-by: Yash Suthar --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7b374fb233..c61d46c4da 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -466,7 +466,7 @@ jobs: uses: actions/checkout@v5 with: fetch-depth: 0 - ref: ${{ github.event.pull_request.head.ref || github.ref_name }} + ref: ${{ github.head_ref || github.ref_name }} - name: Setup Rust uses: dtolnay/rust-toolchain@stable From 012693fe255a0299f9e95c19240c93a2d14b680b Mon Sep 17 00:00:00 2001 From: Yash Suthar Date: Sat, 8 Nov 2025 23:11:57 +0530 Subject: [PATCH 4/5] Added a seprate auto format workflow Signed-off-by: Yash Suthar --- .github/workflows/pr-auto-commit.yaml | 99 +++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .github/workflows/pr-auto-commit.yaml diff --git a/.github/workflows/pr-auto-commit.yaml b/.github/workflows/pr-auto-commit.yaml new file mode 100644 index 0000000000..8546c2abe5 --- /dev/null +++ b/.github/workflows/pr-auto-commit.yaml @@ -0,0 +1,99 @@ +name: PR Auto-format + +# This workflow triggers when a PR is opened/updated +on: + pull_request_target: + types: [opened, synchronize, reopened] + branches: + - main + - release + +concurrency: + group: pr-fmt-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + 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 + + steps: + - name: Checkout PR branch + uses: actions/checkout@v5 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + + # Wait for all PR check runs to complete + - name: Wait for all checks to complete + uses: poseidon/wait-for-status-checks@v0.6.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + delay: 60 + interval: 30 + timeout: 7200 + + - name: CI completed successfully + run: echo "CI workflow completed successfully - proceeding with auto-format" + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: Run cargo fmt + run: | + echo "Running cargo fmt --all on PR #${{ github.event.pull_request.number }}" + cargo fmt --all + + - name: Check for formatting changes + id: check_changes + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "has_changes=true" >> $GITHUB_OUTPUT + else + echo "has_changes=false" >> $GITHUB_OUTPUT + fi + + - 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 }} + + - name: Comment on PR + if: steps.check_changes.outputs.has_changes == 'true' + 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 }} + ``` + + - name: No formatting needed + if: steps.check_changes.outputs.has_changes == 'false' + run: echo "Code is already properly formatted" From 9bfaab725476de1dc1c5bd05a582a075070892dc Mon Sep 17 00:00:00 2001 From: Yash Suthar Date: Tue, 11 Nov 2025 01:35:00 +0530 Subject: [PATCH 5/5] remove old auto-formte implimentaion Signed-off-by: Yash Suthar --- .github/workflows/ci.yaml | 52 --------------------------------------- 1 file changed, 52 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c61d46c4da..2ce4b47577 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -448,55 +448,3 @@ jobs: run: wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/extra_tests/snippets/stdlib_random.py - name: run cpython unittest run: wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/Lib/test/test_int.py - - auto_format_commit: - needs: [rust_tests, exotic_targets, snippets_cpython, lint, miri, wasm, wasm-wasi] - permissions: - contents: write - pull-requests: write - name: Auto-format code - runs-on: ubuntu-latest - if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }} - concurrency: - group: fmt-${{ github.ref }} - cancel-in-progress: true - - steps: - - name: Checkout code - uses: actions/checkout@v5 - with: - fetch-depth: 0 - ref: ${{ github.head_ref || github.ref_name }} - - - name: Setup Rust - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt - - - name: Run cargo fmt - run: | - echo "Running cargo fmt --all" - cargo fmt --all - - - name: Commit and push if changes - id: commit - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - if [ -n "$(git status --porcelain)" ]; then - git add -u - git commit -m "Auto-format code [skip ci]" - git push - echo "formatted=true" >> $GITHUB_OUTPUT - else - echo "formatted=false" >> $GITHUB_OUTPUT - fi - - - name: Comment on PR if formatting was applied - if: steps.commit.outputs.formatted == 'true' && github.event_name == 'pull_request' - uses: marocchino/sticky-pull-request-comment@v2 - with: - message: | - Code has been automatically formatted. - No action needed. - the changes were committed with `[skip ci]`.