base > docs > workflows > Prettier Workflow
The Prettier workflow, defined in .github/workflows/prettier.yml, automates code formatting for the entire repository.
This workflow is triggered on:
pushto themainbranch- Any
pull_request
This job runs on ubuntu-latest and performs the following steps:
- Checkout Code: Checks out the repository's code. It uses the
GITHUB_TOKENto allow the workflow to push changes back to the repository. - Setup Node.js: Sets up Node.js version 20 and configures caching for
npmto speed up dependency installation. - Install Dependencies: Installs the project's dependencies, including Prettier, by running
npm install. - Run Prettier: Executes
npx prettier --write .to format all files in the repository in-place. - Commit Changes: Uses the
stefanzweifel/git-auto-commit-actionto check if Prettier made any changes. If there are changes, it commits them back to the current branch with the commit message "style: Format code with Prettier". This action is configured to check all files.
The purpose of this workflow is to ensure that all code in the repository is consistently formatted according to the Prettier rules, without requiring developers to run Prettier manually before committing.