Repository navigation
66 lines (58 loc) · 2.22 KB
/
Copy pathcode-format-check.yml
File metadata and controls
66 lines (58 loc) · 2.22 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
name: Code Format Check
on:
pull_request:
branches: [ main ]
paths:
- '**.c'
- '**.cpp'
- '**.h'
- '**.hpp'
- '**.cc'
- '**.cxx'
jobs:
format-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch base branch
run: |
git fetch origin ${{ github.base_ref }} --depth=1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install clang-format
run: |
python -m pip install --disable-pip-version-check clang-format==14.0.6
clang-format --version
- name: Run format check
run: |
python script/check_format.py --base origin/${{ github.base_ref }}
- name: Summary on failure
if: failure()
run: |
echo "## ❌ Code Format Check Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Some C/C++ files do not comply with the code format standards." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Checks performed:**" >> $GITHUB_STEP_SUMMARY
echo "- clang-format style check (.clang-format)" >> $GITHUB_STEP_SUMMARY
echo "- Chinese character detection" >> $GITHUB_STEP_SUMMARY
echo "- File header validation (@file, @brief, @copyright)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**How to fix:**" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo '# Auto-format files' >> $GITHUB_STEP_SUMMARY
echo 'clang-format -style=file -i <file>' >> $GITHUB_STEP_SUMMARY
echo '# Or run locally to check' >> $GITHUB_STEP_SUMMARY
echo 'python script/check_format.py --debug --files <file>' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: Summary on success
if: success()
run: |
echo "## ✅ Code Format Check Passed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All modified C/C++ files comply with format standards." >> $GITHUB_STEP_SUMMARY