Skip to content

Commit aae26a3

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 aae26a3

File tree

2 files changed

+64
-52
lines changed

2 files changed

+64
-52
lines changed

.github/workflows/auto-format.yaml

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