-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (42 loc) · 1.45 KB
/
prettier-fixes.yml
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
name: Auto formatter
on:
push:
branches-ignore:
- main
- gh-readonly-queue/main/**
jobs:
prettier:
name: Prettier
runs-on: ubuntu-latest
# Circuit breaker: Avoid a hayewire bot infinitely committing changes if something goes wrong
if: ${{ github.event.head_commit.message != '[Bot] Prettier fixes' }}
steps:
- uses: actions/checkout@v4
with:
# This makes git push to work and other workflows to run
token: ${{ secrets.GIT_TOKEN }}
- uses: pnpm/action-setup@v4
with:
version: 8
- name: Install Node.js dependencies
run: pnpm install
- name: Prettier format changed files
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
# Check for changed files in the PR and fallback to previous commit if direct push
CHANGED_FILES=$(gh pr diff --name-only 2> /dev/null || git diff --name-only HEAD^ HEAD)
echo "Changed Files:"
echo $CHANGED_FILES
if [ -n "$CHANGED_FILES" ]; then
pnpm exec prettier --write $CHANGED_FILES
fi
- name: Commit files
continue-on-error: true
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -a -m "[Bot] Prettier fixes"
- name: Push changes
run: git push