forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (107 loc) · 3.94 KB
/
pr-auto-commit.yaml
File metadata and controls
122 lines (107 loc) · 3.94 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Auto-format PR
# This workflow triggers when a PR is opened/updated
on:
pull_request_target:
types: [opened, synchronize, reopened]
branches:
- main
- release
concurrency:
group: auto-format-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
auto_format:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout PR branch
uses: actions/checkout@v6.0.2
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.AUTO_COMMIT_PAT }}
fetch-depth: 0
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
echo "" > /tmp/committed_commands.txt
- name: Run cargo fmt
run: |
echo "Running cargo fmt --all on PR #${{ github.event.pull_request.number }}"
cargo fmt --all
if [ -n "$(git status --porcelain)" ]; then
git add -u
git commit -m "Auto-format: cargo fmt --all"
echo "- \`cargo fmt --all\`" >> /tmp/committed_commands.txt
fi
- name: Install ruff
uses: astral-sh/ruff-action@4919ec5cf1f49eff0871dbcea0da843445b837e6 # v3.6.1
with:
version: "0.15.4"
args: "--version"
- name: Run ruff format
run: |
ruff format
if [ -n "$(git status --porcelain)" ]; then
git add -u
git commit -m "Auto-format: ruff format"
echo "- \`ruff format\`" >> /tmp/committed_commands.txt
fi
- name: Run ruff check import sorting
run: |
ruff check --select I --fix
if [ -n "$(git status --porcelain)" ]; then
git add -u
git commit -m "Auto-format: ruff check --select I --fix"
echo "- \`ruff check --select I --fix\`" >> /tmp/committed_commands.txt
fi
- name: Run generate_opcode_metadata.py
run: |
python scripts/generate_opcode_metadata.py
if [ -n "$(git status --porcelain)" ]; then
git add -u
git commit -m "Auto-generate: generate_opcode_metadata.py"
echo "- \`python scripts/generate_opcode_metadata.py\`" >> /tmp/committed_commands.txt
fi
- name: Check for changes
id: check-changes
run: |
if [ "$(git rev-parse HEAD)" != "${{ github.event.pull_request.head.sha }}" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
- name: Push formatting changes
if: steps.check-changes.outputs.has_changes == 'true'
env:
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
git push origin "HEAD:${HEAD_REF}"
- name: Read committed commands
id: committed-commands
if: steps.check-changes.outputs.has_changes == 'true'
run: |
echo "list<<EOF" >> $GITHUB_OUTPUT
cat /tmp/committed_commands.txt >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- 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:
${{ steps.committed-commands.outputs.list }}
Please pull the latest changes before pushing again:
```bash
git pull origin ${{ github.event.pull_request.head.ref }}
```