-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e5e043
commit 18ff85c
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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@v2 | ||
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 |