Skip to content

Commit 4760c69

Browse files
committed
Seprate the job to a new workflow as we not need branch restriction
Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
1 parent 4755b21 commit 4760c69

File tree

2 files changed

+65
-52
lines changed

2 files changed

+65
-52
lines changed

.github/workflows/auto-format.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
on:
2+
workflow_run:
3+
workflows: ["CI"]
4+
types:
5+
- completed
6+
workflow_dispatch:
7+
8+
name: Auto format
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
auto_format_commit:
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
name: Auto-format code
20+
runs-on: ubuntu-latest
21+
if: ${{ github.event.workflow_run.conclusion == 'success' && !contains(github.event.workflow_run.head_commit.message, '[skip ci]') }}
22+
concurrency:
23+
group: fmt-${{ github.event.workflow_run.head_branch }}
24+
cancel-in-progress: true
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v5
29+
with:
30+
fetch-depth: 0
31+
ref: ${{ github.event.workflow_run.head_branch }}
32+
repository: ${{ github.event.workflow_run.head_repository.full_name }}
33+
34+
- name: Setup Rust
35+
uses: dtolnay/rust-toolchain@stable
36+
with:
37+
components: rustfmt
38+
39+
- name: Run cargo fmt
40+
run: |
41+
echo "Running cargo fmt --all"
42+
cargo fmt --all
43+
44+
- name: Commit and push if changes
45+
id: commit
46+
run: |
47+
git config user.name "github-actions[bot]"
48+
git config user.email "github-actions[bot]@users.noreply.github.com"
49+
if [ -n "$(git status --porcelain)" ]; then
50+
git add -u
51+
git commit -m "Auto-format code [skip ci]"
52+
git push
53+
echo "formatted=true" >> $GITHUB_OUTPUT
54+
else
55+
echo "formatted=false" >> $GITHUB_OUTPUT
56+
fi
57+
58+
- name: Comment on PR if formatting was applied
59+
if: steps.commit.outputs.formatted == 'true' && github.event_name == 'pull_request'
60+
uses: marocchino/sticky-pull-request-comment@v2
61+
with:
62+
message: |
63+
Code has been automatically formatted.
64+
No action needed.
65+
the changes were committed with `[skip ci]`.

.github/workflows/ci.yaml

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -448,55 +448,3 @@ jobs:
448448
run: wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/extra_tests/snippets/stdlib_random.py
449449
- name: run cpython unittest
450450
run: wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/Lib/test/test_int.py
451-
452-
auto_format_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

Comments
 (0)