Skip to content

Commit 87a7446

Browse files
committed
Auto-fix file format
1 parent d5f7925 commit 87a7446

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

.github/workflows/format.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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: Install python
22+
uses: actions/setup-python@v3
23+
24+
- name: Install pre-commit
25+
run: |
26+
python3 -m pip install pre-commit
27+
pre-commit install
28+
29+
- name: Format files
30+
continue-on-error: true
31+
id: check
32+
run: |
33+
FILES=$(git diff --name-only HEAD origin/$GITHUB_BASE_REF | tr '\n' ' ')
34+
echo $FILES
35+
pre-commit run --files $FILES
36+
37+
- name: Push formatted fixes
38+
if: steps.check.outcome == 'failure'
39+
run: |
40+
git config user.name "Bot"
41+
git config user.email "<[email protected]>"
42+
git commit -am "Fix file format [skip ci]"
43+
git push origin HEAD:${{github.event.pull_request.head.ref}}

0 commit comments

Comments
 (0)