-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (67 loc) · 2.42 KB
/
format.yml
File metadata and controls
78 lines (67 loc) · 2.42 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Auto-format code
on:
pull_request_target:
types: [opened, synchronize, reopened]
branches:
- main
jobs:
auto_format:
if: >
(
github.event.pull_request.user.login == 'dependabot[bot]' ||
contains(
fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'),
github.event.pull_request.author_association
)
) &&
github.repository == 'hakatashi/solid-start-firebase-template'
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.USER_GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 22
cache: "npm"
- name: Setup Biome
uses: biomejs/setup-biome@v2
- name: Check if formatting is needed
id: format-check
run: |
# Run biome format and check if any files were changed
biome format --write .
if git diff --quiet; then
echo "formatting_needed=false" >> $GITHUB_OUTPUT
else
echo "formatting_needed=true" >> $GITHUB_OUTPUT
fi
- name: Check last commit message
id: commit-check
if: steps.format-check.outputs.formatting_needed == 'true'
run: |
LAST_COMMIT_MSG=$(git log -1 --pretty=format:'%s')
if [ "$LAST_COMMIT_MSG" = "Auto-format code with biome" ]; then
echo "should_commit=false" >> $GITHUB_OUTPUT
echo "Last commit was already an auto-format commit. Skipping to prevent infinite loop."
else
echo "should_commit=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push formatting changes
if: steps.format-check.outputs.formatting_needed == 'true' && steps.commit-check.outputs.should_commit == 'true'
run: |
git config --local user.email "hakatasiloving@gmail.com"
git config --local user.name "Koki Takahashi"
git add .
git commit -m "Auto-format code with biome"
git push
- name: Fail if formatting was needed
if: steps.format-check.outputs.formatting_needed == 'true' && steps.commit-check.outputs.should_commit == 'true'
run: |
echo "Code was not properly formatted. Formatting has been applied and committed."
exit 1