1- name : PR Auto-format
1+ name : Auto-format PR
22
33# This workflow triggers when a PR is opened/updated
44on :
99 - release
1010
1111concurrency :
12- group : pr-fmt -${{ github.event.pull_request.number }}
12+ group : auto-format -${{ github.event.pull_request.number }}
1313 cancel-in-progress : true
1414
1515jobs :
1616 auto_format :
17- if : |
18- !contains(github.event.pull_request.labels.*.name, 'skip:ci') &&
19- !contains(github.event.pull_request.head.sha, '[skip ci]')
17+ if : ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }}
2018 permissions :
2119 contents : write
2220 pull-requests : write
23- checks : read
2421 runs-on : ubuntu-latest
2522 timeout-minutes : 60
26-
2723 steps :
2824 - name : Checkout PR branch
2925 uses : actions/checkout@v6
3026 with :
31- ref : ${{ github.event.pull_request.head.ref }}
27+ ref : ${{ github.event.pull_request.head.sha }}
3228 repository : ${{ github.event.pull_request.head.repo.full_name }}
33- token : ${{ secrets.GITHUB_TOKEN }}
29+ token : ${{ secrets.AUTO_COMMIT_PAT }}
3430 fetch-depth : 0
3531
36- # Wait for all PR check runs to complete
37- - name : Wait for all checks to complete
38- uses : poseidon/wait-for-status-checks@v0.6.0
39- with :
40- token : ${{ secrets.GITHUB_TOKEN }}
41- delay : 60
42- interval : 30
43- timeout : 7200
44-
45- - name : CI completed successfully
46- run : echo "CI workflow completed successfully - proceeding with auto-format"
47-
4832 - name : Setup Rust
4933 uses : dtolnay/rust-toolchain@stable
5034 with :
5539 echo "Running cargo fmt --all on PR #${{ github.event.pull_request.number }}"
5640 cargo fmt --all
5741
58- - name : Check for formatting changes
59- id : check_changes
42+ - name : Configure git
43+ run : |
44+ git config user.name "github-actions[bot]"
45+ git config user.email "github-actions[bot]@users.noreply.github.com"
46+
47+ - name : Check for changes
48+ id : check-changes
6049 run : |
6150 if [ -n "$(git status --porcelain)" ]; then
6251 echo "has_changes=true" >> $GITHUB_OUTPUT
@@ -65,35 +54,22 @@ jobs:
6554 fi
6655
6756 - name : Commit and push formatting changes
68- if : steps.check_changes .outputs.has_changes == 'true'
57+ if : steps.check-changes .outputs.has_changes == 'true'
6958 run : |
70- git config user.name "github-actions[bot]"
71- git config user.email "github-actions[bot]@users.noreply.github.com"
72-
7359 git add -u
74- git commit -m "Auto-format code [skip ci]"
75-
60+ git commit -m "Auto-format: cargo fmt --all"
7661 git push origin HEAD:${{ github.event.pull_request.head.ref }}
7762
7863 - name : Comment on PR
79- if : steps.check_changes .outputs.has_changes == 'true'
64+ if : steps.check-changes .outputs.has_changes == 'true'
8065 uses : marocchino/sticky-pull-request-comment@v2
8166 with :
8267 number : ${{ github.event.pull_request.number }}
8368 message : |
8469 **Code has been automatically formatted**
85-
86- The code in this PR has been formatted using `cargo fmt`.
87- The changes have been committed with `[skip ci]` to avoid triggering another CI run.
88-
89- **Triggered by commit:** `${{ github.event.pull_request.head.sha }}`
90- **Last formatted:** ${{ github.event.pull_request.updated_at }}
91-
92- You may need to pull the latest changes before pushing again:
70+
71+ The code in this PR has been formatted using `cargo fmt --all`.
72+ Please pull the latest changes before pushing again:
9373 ```bash
9474 git pull origin ${{ github.event.pull_request.head.ref }}
9575 ```
96-
97- - name : No formatting needed
98- if : steps.check_changes.outputs.has_changes == 'false'
99- run : echo "Code is already properly formatted"
0 commit comments