Last active
September 7, 2024 22:29
-
-
Save o-az/776b137cf86f6e6b31c24234d8a32fd6 to your computer and use it in GitHub Desktop.
This GitHub Action automatically formats code using Prettier when a pull request is opened or updated. It then commits and pushes the formatted code back to the same PR branch, ensuring consistent code style across contributions without manual intervention.
This file contains hidden or 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: 'Auto Commit Prettier' | |
on: | |
pull_request: | |
branches: ['main'] | |
jobs: | |
auto-commit: | |
name: 'Auto Commit' | |
runs-on: ['ubuntu-latest'] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- name: 'checkout' | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: 'format' | |
run: npm_config_yes=true npx prettier@latest --write . | |
- name: 'setup git config' | |
run: | | |
git config --global user.name "Acme Bot" | |
git config --global user.email "[email protected]" | |
- name: 'commit' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git add . --all | |
git commit --all --message "chore: prettier auto commit" | |
git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment