Skip to content

Commit

Permalink
Add GitHub Action to format code with Prettier on push and pull reque…
Browse files Browse the repository at this point in the history
…sts.
  • Loading branch information
Rohit3523 committed Nov 13, 2024
1 parent 28e714d commit 25d5b2d
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/prettier.yml
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

0 comments on commit 25d5b2d

Please sign in to comment.