Automatically format your code with Prettier in GitHub Actions workflows.
- Format code using Prettier in GitHub Actions workflows.
- Customizable Prettier configuration using
.prettierrc
orprettier.config.js
. - Supports formatting JavaScript, TypeScript, CSS, JSON, YAML, and more.
To use this GitHub Action in your workflow, add a step like the following:
- name: Format Code with Prettier
uses: adhikareeprayush/Format-Code@v1
You can configure additional options for Prettier by creating a .prettierrc
or prettier.config.js
file in your repository.
path
: The file or directory path to format (default:.
).prettier-version
: The version of Prettier to use (default: latest).
- name: Format Code with Prettier
uses: adhikareeprayush/format-code@v1
with:
path: 'src/'
prettier-version: '2.7.1'
This action does not provide any outputs.
Here's an example workflow that formats code using Prettier:
name: Format Code
on: [push, pull_request]
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Format Code with Prettier
uses: [email protected]/format-code@v1
with:
path: 'src/'
prettier-version: '2.7.1'
- name: Commit formatted code
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m 'Format code with Prettier'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
This project is licensed under the MIT License - see the LICENSE file for details.
For support or questions, please open an issue in the GitHub repository or contact [email protected].