-
Notifications
You must be signed in to change notification settings - Fork 34
64 lines (55 loc) · 1.71 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
58
59
60
61
62
63
64
name: Code Format
on:
pull_request:
paths:
- 'Growing*/**'
- 'Modules/**'
- 'Services/**'
- 'Package.swift'
permissions:
contents: write
jobs:
code-format:
name: Code Format
runs-on: macos-latest
if: ${{ github.actor != 'GIOSDK' }} # 禁止套娃
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.GIOSDK_PAT }}
- name: Install clang-format
run: brew install clang-format
- name: Install swiftformat
run: swiftformat --version
- name: Code Format
run: |
git fetch
git diff --name-only --relative --diff-filter=ACMR origin/master HEAD \
| sed -E -n '
\%\.pbobjc\.% d
\%^GrowingTrackerCore/Thirdparty/% d
\%^Services/Compression/LZ4/% d
\%^Services/Database/FMDB/% d
\%^Services/WebSocket/% d
\%^(Growing|Modules/|Services/).*\.(h|hpp|c|cpp|m|mm)% p
' \
| xargs clang-format -i -style=file
git diff --name-only --relative --diff-filter=ACMR origin/master HEAD \
| sed -E -n '
\%\.pb\.% d
\%^(Growing|Modules/|Services/).*\.swift% p
\%Package.swift% p
' \
| xargs swiftformat
- name: Commit
run: |
if [[ $(git status) == *"nothing to commit"* ]]; then
echo "All Code formatted correctly."
else
git checkout ${{ github.head_ref }}
git config user.name GIOSDK
git config user.email [email protected]
git commit -am "style: code format"
git push origin ${{ github.head_ref }}
fi