3
3
# SPDX-License-Identifier: Apache-2.0
4
4
5
5
---
6
- name : Auto-Format with Stylelint on PR for "self-healing" PRs
6
+ name : Auto-Format with Stylelint and Prettier on PR for "self-healing" PRs
7
7
8
8
on :
9
9
workflow_call :
@@ -18,26 +18,28 @@ jobs:
18
18
ref : ${{github.event.pull_request.head.ref}}
19
19
fetch-depth : 0
20
20
21
- - name : Check if Stylelint update PR
21
+ - name : Check if Stylelint or Prettier update PR
22
22
id : check_pr
23
23
run : |
24
24
echo "PR title: ${{ github.event.pull_request.title }}"
25
25
if [[ "${{ github.event.pull_request.title }}" =~ "bump stylelint from" ]]; then
26
26
echo "Stylelint update detected."
27
27
echo "stylelint_update=true" >> $GITHUB_ENV
28
+ else if [[ "${{ github.event.pull_request.title }}" =~ "bump prettier from" ]]; then
29
+ echo "Prettier update detected."
30
+ echo "prettier_update=true" >> $GITHUB_ENV
28
31
else
29
- echo "No Stylelint update detected."
30
- echo "stylelint_update=false" >> $GITHUB_ENV
32
+ echo "No Stylelint or prettier updates detected."
31
33
fi
32
34
33
35
- name : Set up Node.js
34
- if : env.stylelint_update == 'true'
36
+ if : env.stylelint_update == 'true' || env.prettier_update == 'true'
35
37
uses : actions/setup-node@v4
36
38
with :
37
39
node-version-file : " .nvmrc"
38
40
39
41
- name : Install dependencies
40
- if : env.stylelint_update == 'true'
42
+ if : env.stylelint_update == 'true' || env.prettier_update == 'true'
41
43
run : |
42
44
npm ci
43
45
@@ -46,13 +48,18 @@ jobs:
46
48
run : |
47
49
npx --no stylelint "**/*.*css" --fix
48
50
51
+ - name : Run Prettier to format the code
52
+ if : env.prettier_update == 'true'
53
+ run : |
54
+ npx --no prettier . --write
55
+
49
56
- name : Commit changes if formatting is done
50
- if : env.stylelint_update == 'true'
57
+ if : env.stylelint_update == 'true' || env.prettier_update == 'true'
51
58
run : |
52
59
git config --global user.name 'github-actions[bot]'
53
60
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
54
61
echo 'COMMIT_MAIL=github-actions[bot]@users.noreply.github.com' >> .env
55
62
56
63
git add .
57
- git commit --all -m "refactor(test): auto-format codebase with Stylelint " || echo "No changes to commit"
64
+ git commit --all -m "refactor(test): auto-format codebase" || echo "No changes to commit"
58
65
git push origin HEAD:${{ github.head_ref }} # Push back to the same PR branch
0 commit comments