-
Notifications
You must be signed in to change notification settings - Fork 5
50 lines (42 loc) · 1.52 KB
/
99-auto-format-dependabot-prettier-updates.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Auto-Format with Prettier on PR for "self-healing" PRs
on:
workflow_call:
jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
fetch-depth: 0
- 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 --no prettier . --write
- 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 --all -m "Auto-format codebase with Prettier" || echo "No changes to commit"
git push origin HEAD:${{ github.head_ref }} # Push back to the same PR branch