Skip to content

Commit 89bb150

Browse files
committed
Auto-fix file format
1 parent d5f7925 commit 89bb150

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

.github/workflows/format.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Auto-fix file format
2+
3+
# Since pre-commit.ci cannot run local hooks, run them here manually to fixup formatting in pull requests
4+
5+
on: pull_request
6+
7+
env:
8+
# SSH Deploy Key with write access (needed to trigger push workflow runs in created pull request)
9+
SSH_KEY: ${{ secrets.SSH_KEY_GITHUB_ACTION }}
10+
11+
jobs:
12+
pre-commit:
13+
name: Format files with pre-commit
14+
runs-on: ubuntu-24.04
15+
steps:
16+
- uses: actions/checkout@v5
17+
with:
18+
ssh-key: ${{ env.SSH_KEY }}
19+
fetch-depth: 0
20+
21+
- name: Bot setup
22+
run: |
23+
AUTHOR=$(git log -1 --pretty=%an)
24+
if [ "$AUTHOR" == "Bot" ]; then
25+
echo "Commit made by bot, skipping further steps in the pipeline."
26+
exit 0
27+
fi
28+
git config user.name "Bot"
29+
git config user.email "<action@github.com>"
30+
31+
- name: Install python
32+
uses: actions/setup-python@v3
33+
34+
- name: Install pre-commit
35+
run: |
36+
python3 -m pip install pre-commit
37+
pre-commit install
38+
39+
- name: Format files
40+
continue-on-error: true
41+
id: check
42+
run: |
43+
FILES=$(git diff --name-only HEAD origin/$GITHUB_BASE_REF | tr '\n' ' ')
44+
echo $FILES
45+
pre-commit run --files $FILES
46+
47+
- name: Push formatting fixes
48+
if: steps.check.outcome == 'failure'
49+
run: |
50+
git commit -am "Fixes formatting"
51+
git push origin HEAD:${{github.event.pull_request.head.ref}}

0 commit comments

Comments
 (0)