Skip to content

feat: auto format dependabot prettier updates #2

feat: auto format dependabot prettier updates

feat: auto format dependabot prettier updates #2

name: Auto-Format with Prettier on PR for "self-healing" PRs
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: |
npm ci
- name: Check if Prettier update PR
id: check_pr
run: |
echo "PR title: ${{ github.event.pull_request.title }}"
if [[ "${{ github.event.pull_request.title }}" =~ "bump prettier from" ]]; then
echo "Prettier update detected."
echo "prettier_update=true" >> $GITHUB_ENV
else
echo "No Prettier update detected."
echo "prettier_update=false" >> $GITHUB_ENV
fi
- name: Run Prettier to format the code
if: env.prettier_update == 'true'
run: |
npx prettier --write . # Adjust to target your specific files or folder
- name: Commit changes if formatting is done
if: env.prettier_update == 'true'
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 "Auto-format codebase with Prettier" || echo "No changes to commit"
git push origin HEAD:${{ github.head_ref }}