test feel free to ignore #15
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: Prettier Format and Commit | |
on: | |
pull_request: | |
branches: | |
- main | |
- 'refs/heads/*' | |
jobs: | |
prettier: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 'latest' | |
- name: Install dependencies | |
run: npm install | |
- name: Run Prettier | |
run: npx prettier --write . | |
- name: Commit changes | |
id: commit | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
if git diff-index --quiet HEAD; then | |
echo "No changes to commit." | |
echo "changes_committed=false" >> $GITHUB_ENV | |
else | |
git commit -m "chore: format code with Prettier" | |
echo "changes_committed=true" >> $GITHUB_ENV | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push changes | |
if: env.changes_committed == 'true' | |
run: git push origin HEAD:${{ github.event.pull_request.head.ref }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |