-
Notifications
You must be signed in to change notification settings - Fork 305
43 lines (36 loc) · 1.31 KB
/
clang-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
name: ClangFormat Lint
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
clang-format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install clang-format
run: sudo apt-get install -y clang-format
- name: Get changed files
id: changed-files
run: |
if [ ${{ github.event_name }} == 'pull_request' ]; then
# For pull requests, compare against the base branch
echo "FILES=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -E '\.(cpp|h)$' | xargs)" >> $GITHUB_OUTPUT
else
# For pushes, compare against the parent commit
echo "FILES=$(git diff --name-only --diff-filter=ACMRT ${{ github.event.before }} ${{ github.sha }} | grep -E '\.(cpp|h)$' | xargs)" >> $GITHUB_OUTPUT
fi
- name: Run clang-format
run: |
for file in ${{ steps.changed-files.outputs.FILES }}; do
clang-format -style=file -i "$file"
done
git diff --exit-code
- name: Suggest changes if formatting is incorrect
if: failure()
run: |
echo "::error::Formatting issues found. Please run clang-format on your changes and commit the results."
git diff