Skip to content

Commit 449d3d1

Browse files
authored
feat: auto format dependabot prettier updates (#157)
* feat: auto format dependabot prettier updates * Create .nvmrc * Update 99-auto-format-dependabot-prettier-updates.yml * Update 99-auto-format-dependabot-prettier-updates.yml * Update pull-request.yml * Update 99-auto-format-dependabot-prettier-updates.yml * Update pull-request.yml
1 parent 4f915f7 commit 449d3d1

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
git add .
45+
git commit -m "Auto-format codebase with Prettier" || echo "No changes to commit"
46+
git push origin HEAD:${{ github.head_ref }}

.github/workflows/pull-request.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ name: On-PR to main
44
on:
55
pull_request:
66
branches: ["main"]
7+
types: [opened, synchronize, reopened]
78
merge_group:
89
branches: ["main"]
910

@@ -17,6 +18,9 @@ jobs:
1718
dependabot:
1819
uses: ./.github/workflows/99-auto-merge.yml
1920

21+
dependabot-prettier-self-healing:
22+
uses: ./.github/workflows/99-auto-format-dependabot-prettier-updates.yml
23+
2024
codeql:
2125
uses: ./.github/workflows/99-codeql-analysis.yml
2226

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

0 commit comments

Comments
 (0)