forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (82 loc) · 3.18 KB
/
pr-auto-commit.yaml
File metadata and controls
99 lines (82 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: PR Auto-format
# This workflow triggers when a PR is opened/updated
on:
pull_request_target:
types: [opened, synchronize, reopened]
branches:
- main
- release
concurrency:
group: pr-fmt-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
auto_format:
if: |
!contains(github.event.pull_request.labels.*.name, 'skip:ci') &&
!contains(github.event.pull_request.head.sha, '[skip ci]')
permissions:
contents: write
pull-requests: write
checks: read
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout PR branch
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
# Wait for all PR check runs to complete
- name: Wait for all checks to complete
uses: poseidon/wait-for-status-checks@v0.6.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
delay: 60
interval: 30
timeout: 7200
- name: CI completed successfully
run: echo "CI workflow completed successfully - proceeding with auto-format"
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Run cargo fmt
run: |
echo "Running cargo fmt --all on PR #${{ github.event.pull_request.number }}"
cargo fmt --all
- name: Check for formatting changes
id: check_changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push formatting changes
if: steps.check_changes.outputs.has_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -u
git commit -m "Auto-format code [skip ci]"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
- name: Comment on PR
if: steps.check_changes.outputs.has_changes == 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.pull_request.number }}
message: |
**Code has been automatically formatted**
The code in this PR has been formatted using `cargo fmt`.
The changes have been committed with `[skip ci]` to avoid triggering another CI run.
**Triggered by commit:** `${{ github.event.pull_request.head.sha }}`
**Last formatted:** ${{ github.event.pull_request.updated_at }}
You may need to pull the latest changes before pushing again:
```bash
git pull origin ${{ github.event.pull_request.head.ref }}
```
- name: No formatting needed
if: steps.check_changes.outputs.has_changes == 'false'
run: echo "Code is already properly formatted"