@@ -34,42 +34,77 @@ jobs:
3434 with :
3535 components : rustfmt
3636
37+ - name : Configure git
38+ run : |
39+ git config user.name "github-actions[bot]"
40+ git config user.email "github-actions[bot]@users.noreply.github.com"
41+ echo "" > /tmp/committed_commands.txt
42+
3743 - name : Run cargo fmt
3844 run : |
3945 echo "Running cargo fmt --all on PR #${{ github.event.pull_request.number }}"
4046 cargo fmt --all
47+ if [ -n "$(git status --porcelain)" ]; then
48+ git add -u
49+ git commit -m "Auto-format: cargo fmt --all"
50+ echo "- \`cargo fmt --all\`" >> /tmp/committed_commands.txt
51+ fi
4152
4253 - name : Install ruff
4354 uses : astral-sh/ruff-action@57714a7c8a2e59f32539362ba31877a1957dded1 # v3.5.1
4455 with :
45- version : " 0.14.9 "
56+ version : " 0.14.11 "
4657 args : " --version"
4758
48- - run : ruff format
49- - run : ruff check --select I --fix
50- - run : python scripts/generate_opcode_metadata.py
59+ - name : Run ruff format
60+ run : |
61+ ruff format
62+ if [ -n "$(git status --porcelain)" ]; then
63+ git add -u
64+ git commit -m "Auto-format: ruff format"
65+ echo "- \`ruff format\`" >> /tmp/committed_commands.txt
66+ fi
5167
52- - name : Configure git
68+ - name : Run ruff check import sorting
5369 run : |
54- git config user.name "github-actions[bot]"
55- git config user.email "github-actions[bot]@users.noreply.github.com"
70+ ruff check --select I --fix
71+ if [ -n "$(git status --porcelain)" ]; then
72+ git add -u
73+ git commit -m "Auto-format: ruff check --select I --fix"
74+ echo "- \`ruff check --select I --fix\`" >> /tmp/committed_commands.txt
75+ fi
76+
77+ - name : Run generate_opcode_metadata.py
78+ run : |
79+ python scripts/generate_opcode_metadata.py
80+ if [ -n "$(git status --porcelain)" ]; then
81+ git add -u
82+ git commit -m "Auto-generate: generate_opcode_metadata.py"
83+ echo "- \`python scripts/generate_opcode_metadata.py\`" >> /tmp/committed_commands.txt
84+ fi
5685
5786 - name : Check for changes
5887 id : check-changes
5988 run : |
60- if [ -n "$(git status --porcelain) " ]; then
89+ if [ "$(git rev-parse HEAD)" != "${{ github.event.pull_request.head.sha }} " ]; then
6190 echo "has_changes=true" >> $GITHUB_OUTPUT
6291 else
6392 echo "has_changes=false" >> $GITHUB_OUTPUT
6493 fi
6594
66- - name : Commit and push formatting changes
95+ - name : Push formatting changes
6796 if : steps.check-changes.outputs.has_changes == 'true'
6897 run : |
69- git add -u
70- git commit -m "Auto-format: cargo fmt --all"
7198 git push origin HEAD:${{ github.event.pull_request.head.ref }}
7299
100+ - name : Read committed commands
101+ id : committed-commands
102+ if : steps.check-changes.outputs.has_changes == 'true'
103+ run : |
104+ echo "list<<EOF" >> $GITHUB_OUTPUT
105+ cat /tmp/committed_commands.txt >> $GITHUB_OUTPUT
106+ echo "EOF" >> $GITHUB_OUTPUT
107+
73108 - name : Comment on PR
74109 if : steps.check-changes.outputs.has_changes == 'true'
75110 uses : marocchino/sticky-pull-request-comment@v2
78113 message : |
79114 **Code has been automatically formatted**
80115
81- The code in this PR has been formatted using `cargo fmt --all`.
116+ The code in this PR has been formatted using:
117+ ${{ steps.committed-commands.outputs.list }}
82118 Please pull the latest changes before pushing again:
83119 ```bash
84120 git pull origin ${{ github.event.pull_request.head.ref }}
0 commit comments