Skip to content

chore: Add Prettier auto-formatting GitHub Action #2

chore: Add Prettier auto-formatting GitHub Action

chore: Add Prettier auto-formatting GitHub Action #2

Workflow file for this run

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
with:
ref: ${{ github.head_ref || github.ref_name }}
fetch-depth: 0
- 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 origin HEAD:${{ github.head_ref || github.ref_name }}