-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (92 loc) · 3.95 KB
/
pre-commit.yaml
File metadata and controls
111 lines (92 loc) · 3.95 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Pre-Commit Checks
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
# ============================================================================
# Pre-Commit Format Check
# ============================================================================
pre-commit-format:
name: Format Check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install clang-format
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 21
sudo apt-get install -y clang-format-21
sudo ln -sf /usr/bin/clang-format-21 /usr/bin/clang-format
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
with:
files: |
src/**/*.cpp
src/**/*.hpp
src/**/*.h
tests/**/*.cpp
tests/**/*.hpp
examples/**/*.cpp
examples/**/*.hpp
- name: Check formatting of changed files
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo "Checking formatting for changed files..."
echo ""
python3 scripts/format.py --check ${{ steps.changed-files.outputs.all_changed_files }}
- name: Comment on PR (if formatting fails)
if: failure()
uses: actions/github-script@v7
with:
script: |
const issue_number = context.issue.number;
const body = `## ❌ Code Formatting Check Failed
Some files in this PR do not follow the project's formatting guidelines.
### How to fix:
Run the formatting script locally (requires clang-format 21+):
\`\`\`bash
python scripts/format.py
\`\`\`
Or manually format the files:
\`\`\`bash
clang-format -i -style=file <file>
\`\`\`
Then commit and push the changes.
**Note:** Make sure you're using clang-format version 21+. Check with \`clang-format --version\`.
### CI will automatically re-check once you push the fixes.
`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: body
});
- name: Comment on PR (if formatting passes)
if: success() && steps.changed-files.outputs.any_changed == 'true'
uses: actions/github-script@v7
with:
script: |
const issue_number = context.issue.number;
const body = `## ✅ Code Formatting Check Passed
All files in this PR follow the project's formatting guidelines.
`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: body
});