@@ -307,15 +307,13 @@ jobs:
307307 run : python -I whats_left.py
308308
309309 lint :
310- name : Check Rust code with rustfmt and clippy
310+ name : Check Rust code with clippy
311311 runs-on : ubuntu-latest
312312 steps :
313313 - uses : actions/checkout@v5
314314 - uses : dtolnay/rust-toolchain@stable
315315 with :
316- components : rustfmt, clippy
317- - name : run rustfmt
318- run : cargo fmt --check
316+ components : clippy
319317 - name : run clippy on wasm
320318 run : cargo clippy --manifest-path=wasm/lib/Cargo.toml -- -Dwarnings
321319 - uses : actions/setup-python@v6
@@ -450,3 +448,55 @@ jobs:
450448 run : wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/extra_tests/snippets/stdlib_random.py
451449 - name : run cpython unittest
452450 run : wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/Lib/test/test_int.py
451+
452+ auto_formate_commit :
453+ needs : [rust_tests, exotic_targets, snippets_cpython, lint, miri, wasm, wasm-wasi]
454+ permissions :
455+ contents : write
456+ pull-requests : write
457+ name : Auto-format code
458+ runs-on : ubuntu-latest
459+ if : ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
460+ concurrency :
461+ group : fmt-${{ github.ref }}
462+ cancel-in-progress : true
463+
464+ steps :
465+ - name : Checkout code
466+ uses : actions/checkout@v5
467+ with :
468+ fetch-depth : 0
469+ ref : ${{ github.head_ref || github.ref_name }}
470+
471+ - name : Setup Rust
472+ uses : dtolnay/rust-toolchain@stable
473+ with :
474+ components : rustfmt
475+
476+ - name : Run cargo fmt
477+ run : |
478+ echo "Running cargo fmt --all"
479+ cargo fmt --all
480+
481+ - name : Commit and push if changes
482+ id : commit
483+ run : |
484+ git config user.name "github-actions[bot]"
485+ git config user.email "github-actions[bot]@users.noreply.github.com"
486+ if [ -n "$(git status --porcelain)" ]; then
487+ git add -u
488+ git commit -m "Auto-format code [skip ci]"
489+ git push
490+ echo "formatted=true" >> $GITHUB_OUTPUT
491+ else
492+ echo "formatted=false" >> $GITHUB_OUTPUT
493+ fi
494+
495+ - name : Comment on PR if formatting was applied
496+ if : steps.commit.outputs.formatted == 'true' && github.event_name == 'pull_request'
497+ uses : marocchino/sticky-pull-request-comment@v2
498+ with :
499+ message : |
500+ Code has been automatically formatted.
501+ No action needed.
502+ the changes were committed with `[skip ci]`.
0 commit comments