Skip to content

Commit 3f9126a

Browse files
Merge b8e60bd into 01d4925
2 parents 01d4925 + b8e60bd commit 3f9126a

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
with:
13+
ref: ${{ github.ref }}
14+
fetch-depth: 0
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version-file: '.nvmrc'
20+
21+
- name: Install dependencies
22+
run: |
23+
npm ci
24+
25+
- name: Check if Prettier update PR
26+
id: check_pr
27+
run: |
28+
echo "PR title: ${{ github.event.pull_request.title }}"
29+
if [[ "${{ github.event.pull_request.title }}" =~ "bump prettier from" ]]; then
30+
echo "Prettier update detected."
31+
echo "prettier_update=true" >> $GITHUB_ENV
32+
else
33+
echo "No Prettier update detected."
34+
echo "prettier_update=false" >> $GITHUB_ENV
35+
fi
36+
37+
- name: Run Prettier to format the code
38+
if: env.prettier_update == 'true'
39+
run: |
40+
npx --no prettier . --write
41+
42+
- name: Commit changes if formatting is done
43+
if: env.prettier_update == 'true'
44+
run: |
45+
git config --global user.name 'github-actions[bot]'
46+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
47+
48+
git add .
49+
git commit --all -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

.github/workflows/pull-request.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
auto-merge:
1616
uses: ./.github/workflows/99-auto-merge.yml
1717

18+
dependabot-prettier-self-healing:
19+
uses: ./.github/workflows/99-auto-format-dependabot-prettier-updates.yml
20+
1821
codeql:
1922
uses: ./.github/workflows/99-codeql-analysis.yml
2023

package-lock.json

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"postcss-cli": "^11.0.1",
9595
"postcss-focus": "^7.0.0",
9696
"postcss-list-style-safari-fix": "^1.0.0",
97-
"prettier": "^3.4.2",
97+
"prettier": "^3.5.3",
9898
"rimraf": "^6.0.1",
9999
"sass": "^1.87.0",
100100
"start-server-and-test": "^2.0.11",

0 commit comments

Comments
 (0)