File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Auto-Format with Prettier on PR for "self-healing" PRs
2
+
3
+ on :
4
+ workflow_call :
5
+
6
+ jobs :
7
+ format :
8
+ runs-on : ubuntu-latest
9
+ steps :
10
+ - name : Checkout code
11
+ uses : actions/checkout@v4
12
+
13
+ - name : Set up Node.js
14
+ uses : actions/setup-node@v4
15
+ with :
16
+ node-version-file : ' .nvmrc'
17
+
18
+ - name : Install dependencies
19
+ run : |
20
+ npm ci
21
+
22
+ - name : Check if Prettier update PR
23
+ id : check_pr
24
+ run : |
25
+ echo "PR title: ${{ github.event.pull_request.title }}"
26
+ if [[ "${{ github.event.pull_request.title }}" =~ "bump prettier from" ]]; then
27
+ echo "Prettier update detected."
28
+ echo "prettier_update=true" >> $GITHUB_ENV
29
+ else
30
+ echo "No Prettier update detected."
31
+ echo "prettier_update=false" >> $GITHUB_ENV
32
+ fi
33
+
34
+ - name : Run Prettier to format the code
35
+ if : env.prettier_update == 'true'
36
+ run : |
37
+ npx --no prettier --write .
38
+
39
+ - name : Commit changes if formatting is done
40
+ if : env.prettier_update == 'true'
41
+ run : |
42
+ git config --global user.name 'github-actions[bot]'
43
+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
44
+
45
+ # Checkout the PR branch (already done by actions/checkout)
46
+ git checkout ${{ github.head_ref }} # This ensures we're on the PR branch
47
+
48
+ git add .
49
+ git commit -m "Auto-format codebase with Prettier" || echo "No changes to commit"
50
+ git push origin HEAD:${{ github.head_ref }} # Push back to the same PR branch
You can’t perform that action at this time.
0 commit comments