Skip to content

Commit be4aa0f

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 be4aa0f

File tree

2 files changed

+73
-52
lines changed

2 files changed

+73
-52
lines changed

.github/workflows/auto-format.yaml

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