-
-
Notifications
You must be signed in to change notification settings - Fork 51
47 lines (38 loc) · 1.38 KB
/
format-check.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
name: Formatting check
on: [pull_request]
jobs:
formatting-check:
name: Formatting check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
# To get a diff from the PR we need to fetch 2 commits.
# The checkout action will create a merge commit as {{ github.sha }}.
fetch-depth: 2
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -yqq clang-format
- name: Format check
id: format-check
run: |
git diff -U0 --no-color ${{ github.sha }}^ -- '*.cpp' '*.c' '*.h' '*.hpp' |
/usr/share/clang/clang-format-16/clang-format-diff.py -p1 > clang-format.patch
# Check if patch is not empty
if [ -s clang-format.patch ]; then
echo "###############################################################"
echo "# Format checks failed!"
echo "# A patch has been uploaded as an artifact and is shown below."
echo "###############################################################"
# Show patch
cat clang-format.patch
exit 1
fi
- name: Upload format fixes patch
uses: actions/upload-artifact@v4
if: ${{ failure() && steps.format-check.outcome == 'failure' }}
with:
name: clang-format.patch
path: clang-format.patch
if-no-files-found: ignore