Run Prettier on Github Actions


How to run

  1. Add the following job to your workflow
jobs:
  run-prettier:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.GH_TOKEN }}
          ref: ${{ github.head_ref }}
      - run: |
          npx prettier --write .
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add . 
          git commit -m "Automatic Changes"  || echo "no changes"
          git push || echo "no changes"
  1. Make sure to have the following permissions
permissions:
packages: write
contents: write
deployments: write
pull-requests: write
issues: write
pages: write
id-token: write
repository-projects: write

Checkout the source code of this website for a more detailed example.