Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit 33e12e2

Browse files
committed
feat: automate committing formatted code in GitHub Actions
1 parent 83a6689 commit 33e12e2

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

.github/workflows/format.yml

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
name: Format Code
22

33
on:
4-
pull_request:
5-
branches:
6-
- dev
4+
pull_request:
5+
branches:
6+
- dev
77

88
jobs:
9-
prettier-format:
10-
runs-on: ubuntu-latest
9+
prettier-format:
10+
runs-on: ubuntu-latest
1111

12-
steps:
13-
- name: Checkout repository
14-
uses: actions/checkout@v2
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v2
1515

16-
- name: Set up Node.js
17-
uses: actions/setup-node@v2
18-
with:
19-
node-version: '20'
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: '20'
2020

21-
- name: Install dependencies
22-
run: npm install
21+
- name: Install dependencies
22+
run: npm install
2323

24-
- name: Run Prettier format
25-
run: npm run format
24+
- name: Run Prettier format
25+
run: npm run format
26+
27+
- name: Commit changes
28+
run: |
29+
git config --global user.name 'github-actions[bot]'
30+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
31+
git add .
32+
if ! git diff-index --quiet HEAD; then
33+
git commit -m 'Format code with Prettier'
34+
git push
35+
fi
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)