-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub Action to format code with Prettier on push and pull reque…
…sts.
- Loading branch information
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: Format Code with Prettier | ||
|
||
on: | ||
push: | ||
branches: | ||
- '*' | ||
- '!develop' | ||
pull_request: | ||
branches: | ||
- '*' | ||
|
||
jobs: | ||
format: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '22' | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Run Prettier | ||
run: yarn prettier --write . | ||
|
||
- name: Check for changes | ||
id: check_changes | ||
run: | | ||
if git diff --quiet; then | ||
echo "No code format changes detected" | ||
echo "changes=false" >> $GITHUB_OUTPUT | ||
else | ||
echo "Code format changes detected" | ||
echo "changes=true" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Commit and push changes | ||
if: steps.check_changes.outputs.changes == 'true' | ||
run: | | ||
git config user.name "${{ github.actor }}" | ||
git config user.email "${{ github.actor }}@users.noreply.github.com" | ||
git add . | ||
git commit -m "chore: format code with Prettier" | ||
git push |