Skip to content

Commit 8b4de46

Browse files
committed
github: Add clang format check workflow.
Signed-off-by: iabdalkader <[email protected]>
1 parent ddb1525 commit 8b4de46

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

.github/workflows/format_check.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: 'Format Check'
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
paths:
8+
- '**/*.{c,cpp,cc,cxx,h,hpp}'
9+
10+
pull_request:
11+
types:
12+
- opened
13+
- edited
14+
- reopened
15+
- synchronize
16+
branches:
17+
- 'main'
18+
paths:
19+
- '**/*.{c,cpp,cc,cxx,h,hpp}'
20+
21+
workflow_dispatch:
22+
inputs:
23+
logLevel:
24+
description: 'Log level'
25+
required: true
26+
default: 'warning'
27+
28+
jobs:
29+
format-check:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
with:
35+
submodules: false
36+
persist-credentials: false
37+
38+
- name: Install clang-format
39+
run: |
40+
sudo apt-get update
41+
sudo apt-get install -y clang-format
42+
43+
- name: Get changed files
44+
id: changed-files
45+
uses: tj-actions/changed-files@v46
46+
with:
47+
files: |
48+
cores/arduino/**/*.{c,cpp,cc,cxx,h,hpp}
49+
!cores/arduino/api/**
50+
loader/**/*.{c,cpp,cc,cxx,h,hpp}
51+
!loader/llext_exports.c
52+
libraries/**/*.{c,cpp,cc,cxx,h,hpp}
53+
54+
- name: Run clang-format check
55+
if: steps.changed-files.outputs.any_changed == 'true'
56+
run: |
57+
exit_code=0
58+
59+
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
60+
file_fmt="${file}.tmp"
61+
clang-format ${file} > ${file_fmt}
62+
diff -q -u ${file} ${file_fmt} >> /dev/null 2>&1 || {
63+
echo "❌ Formatting issues found in: $file"
64+
colordiff -u ${file} ${file_fmt} || true
65+
exit_code=1
66+
}
67+
done
68+
69+
exit $exit_code

0 commit comments

Comments
 (0)