Skip to content

Commit e21c195

Browse files
committed
refactor: added self-healing workflow
1 parent 9cf6e60 commit e21c195

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
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 Stylelint 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.event.pull_request.head.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 Stylelint 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 stylelint from" ]]; then
30+
echo "Stylelint update detected."
31+
echo "stylelint_update=true" >> $GITHUB_ENV
32+
else
33+
echo "No Stylelint update detected."
34+
echo "stylelint_update=false" >> $GITHUB_ENV
35+
fi
36+
37+
- name: Run Stylelint to format the code
38+
if: env.stylelint_update == 'true'
39+
run: |
40+
npx --no stylelint "**/*.*css" --fix
41+
42+
- name: Commit changes if formatting is done
43+
if: env.stylelint_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 Stylelint" || 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
@@ -19,6 +19,9 @@ jobs:
1919
auto-merge:
2020
uses: ./.github/workflows/99-auto-merge.yml
2121

22+
dependabot-stylelint-self-healing:
23+
uses: ./.github/workflows/99-auto-fix-dependabot-stylelint-updates.yml
24+
2225
codeql:
2326
uses: ./.github/workflows/99-codeql-analysis.yml
2427

0 commit comments

Comments
 (0)