-
Notifications
You must be signed in to change notification settings - Fork 15
57 lines (49 loc) · 1.48 KB
/
code-format.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: 🎀 Code Format (Verification)
on:
push:
branches:
- main
- develop
pull_request:
jobs:
code-format:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Code format check
id: fmt_check
continue-on-error: true
run: |
if ! npm run fmt:check; then
echo "exit_code=1" >> "$GITHUB_OUTPUT"
fi
- name: Auto-format (Markdown files)
if: steps.fmt_check.outputs.exit_code != '0' && github.event_name == 'pull_request'
run: npx prettier --write "src/**/*.{md,mdx}"
- name: Commit formatted (Markdown files)
if: steps.fmt_check.outputs.exit_code != '0' && github.event_name == 'pull_request'
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
if [[ -n "$(git status --porcelain)" ]]; then
git add .
if git commit -m "chore: 🤖 code format" --no-verify; then
git push
else
echo "🦖 Skipped! No changes to commit..."
fi
else
echo "🦖 Skipped! No changes found."
fi