chore: Add Prettier auto-formatting GitHub Action #6
Workflow file for this run
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
name: Format Code with Prettier | |
on: | |
push: | |
branches: | |
- '*' | |
- '!develop' | |
pull_request: | |
branches: | |
- '*' | |
jobs: | |
format: | |
if: github.repository == github.event.repository.full_name | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
issues: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.pull_request.head.ref }} | |
repository: ${{ github.event.pull_request.head.repo.full_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 }} |