Skip to content

Commit 0aacc5c

Browse files
committed
feat(ci): autoformat commits
1 parent 6dd4826 commit 0aacc5c

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

.github/workflows/auto-format.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This workflow runs on every push and automatically applies formatting using mise format
2+
name: Auto-format code
3+
4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.ref }}
6+
cancel-in-progress: true
7+
8+
on:
9+
push:
10+
branches:
11+
- "**"
12+
13+
jobs:
14+
format:
15+
runs-on: ubuntu-24.04-arm
16+
# Only run on the main repo, skip forks
17+
# Skip if commit is already from this auto-format workflow to avoid infinite loops
18+
if: github.repository == 'ChainSafe/forest' && !contains(github.event.head_commit.message, '[LeshyBot] Apply automatic formatting')
19+
steps:
20+
- uses: actions/create-github-app-token@v2
21+
id: generate-token
22+
with:
23+
app-id: ${{ secrets.LESHY_APP_ID }}
24+
private-key: ${{ secrets.LESHY_APP_PRIVATE_KEY }}
25+
26+
- uses: actions/checkout@v6
27+
with:
28+
token: ${{ steps.generate-token.outputs.token }}
29+
fetch-depth: 0
30+
31+
- uses: jdx/mise-action@v3
32+
- run: mise format
33+
34+
- name: Check for changes
35+
id: check-changes
36+
run: |
37+
if [[ -n $(git status --porcelain) ]]; then
38+
echo "has_changes=true" >> $GITHUB_OUTPUT
39+
else
40+
echo "has_changes=false" >> $GITHUB_OUTPUT
41+
fi
42+
43+
- name: Commit and push formatting changes
44+
if: steps.check-changes.outputs.has_changes == 'true'
45+
run: |
46+
git config user.name "LeshyBot"
47+
git add .
48+
git commit -m "[LeshyBot] Apply automatic formatting"
49+
git push

0 commit comments

Comments
 (0)