Skip to content

Commit ef0975b

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

File tree

2 files changed

+192
-0
lines changed

2 files changed

+192
-0
lines changed

.clang-format

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Note: The list of ForEachMacros can be obtained using:
4+
#
5+
# git grep -h '^#define [^[:space:]]*FOR_EACH[^[:space:]]*(' include/ \
6+
# | sed "s,^#define \([^[:space:]]*FOR_EACH[^[:space:]]*\)(.*$, - '\1'," \
7+
# | sort | uniq
8+
#
9+
# References:
10+
# - https://clang.llvm.org/docs/ClangFormatStyleOptions.html
11+
12+
---
13+
BasedOnStyle: LLVM
14+
AlignOperands: Align
15+
BreakBeforeTernaryOperators: false
16+
AlignConsecutiveMacros: AcrossComments
17+
AllowShortBlocksOnASingleLine: Never
18+
AllowShortCaseLabelsOnASingleLine: false
19+
AllowShortEnumsOnASingleLine: false
20+
AllowShortFunctionsOnASingleLine: None
21+
AllowShortIfStatementsOnASingleLine: false
22+
AllowShortLoopsOnASingleLine: false
23+
AttributeMacros:
24+
- __aligned
25+
- __deprecated
26+
- __packed
27+
- __printf_like
28+
- __syscall
29+
- __syscall_always_inline
30+
- __subsystem
31+
BitFieldColonSpacing: After
32+
BreakBeforeBraces: Attach
33+
ColumnLimit: 100
34+
ConstructorInitializerIndentWidth: 4
35+
ContinuationIndentWidth: 4
36+
ForEachMacros:
37+
- 'ARRAY_FOR_EACH'
38+
- 'ARRAY_FOR_EACH_PTR'
39+
- 'FOR_EACH'
40+
- 'FOR_EACH_FIXED_ARG'
41+
- 'FOR_EACH_IDX'
42+
- 'FOR_EACH_IDX_FIXED_ARG'
43+
- 'FOR_EACH_NONEMPTY_TERM'
44+
- 'FOR_EACH_FIXED_ARG_NONEMPTY_TERM'
45+
- 'RB_FOR_EACH'
46+
- 'RB_FOR_EACH_CONTAINER'
47+
- 'SYS_DLIST_FOR_EACH_CONTAINER'
48+
- 'SYS_DLIST_FOR_EACH_CONTAINER_SAFE'
49+
- 'SYS_DLIST_FOR_EACH_NODE'
50+
- 'SYS_DLIST_FOR_EACH_NODE_SAFE'
51+
- 'SYS_SEM_LOCK'
52+
- 'SYS_SFLIST_FOR_EACH_CONTAINER'
53+
- 'SYS_SFLIST_FOR_EACH_CONTAINER_SAFE'
54+
- 'SYS_SFLIST_FOR_EACH_NODE'
55+
- 'SYS_SFLIST_FOR_EACH_NODE_SAFE'
56+
- 'SYS_SLIST_FOR_EACH_CONTAINER'
57+
- 'SYS_SLIST_FOR_EACH_CONTAINER_SAFE'
58+
- 'SYS_SLIST_FOR_EACH_NODE'
59+
- 'SYS_SLIST_FOR_EACH_NODE_SAFE'
60+
- '_WAIT_Q_FOR_EACH'
61+
- 'Z_FOR_EACH'
62+
- 'Z_FOR_EACH_ENGINE'
63+
- 'Z_FOR_EACH_EXEC'
64+
- 'Z_FOR_EACH_FIXED_ARG'
65+
- 'Z_FOR_EACH_FIXED_ARG_EXEC'
66+
- 'Z_FOR_EACH_IDX'
67+
- 'Z_FOR_EACH_IDX_EXEC'
68+
- 'Z_FOR_EACH_IDX_FIXED_ARG'
69+
- 'Z_FOR_EACH_IDX_FIXED_ARG_EXEC'
70+
- 'Z_GENLIST_FOR_EACH_CONTAINER'
71+
- 'Z_GENLIST_FOR_EACH_CONTAINER_SAFE'
72+
- 'Z_GENLIST_FOR_EACH_NODE'
73+
- 'Z_GENLIST_FOR_EACH_NODE_SAFE'
74+
- 'STRUCT_SECTION_FOREACH'
75+
- 'STRUCT_SECTION_FOREACH_ALTERNATE'
76+
- 'TYPE_SECTION_FOREACH'
77+
- 'K_SPINLOCK'
78+
- 'COAP_RESOURCE_FOREACH'
79+
- 'COAP_SERVICE_FOREACH'
80+
- 'COAP_SERVICE_FOREACH_RESOURCE'
81+
- 'HTTP_RESOURCE_FOREACH'
82+
- 'HTTP_SERVER_CONTENT_TYPE_FOREACH'
83+
- 'HTTP_SERVICE_FOREACH'
84+
- 'HTTP_SERVICE_FOREACH_RESOURCE'
85+
- 'I3C_BUS_FOR_EACH_I3CDEV'
86+
- 'I3C_BUS_FOR_EACH_I2CDEV'
87+
- 'MIN_HEAP_FOREACH'
88+
IfMacros:
89+
- 'CHECKIF'
90+
IncludeCategories:
91+
- Regex: '^".*\.h"$'
92+
Priority: 0
93+
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|wchar|wctype)\.h>$'
94+
Priority: 1
95+
- Regex: '^\<zephyr/.*\.h\>$'
96+
Priority: 2
97+
- Regex: '.*'
98+
Priority: 3
99+
IndentCaseLabels: false
100+
IndentGotoLabels: false
101+
IndentWidth: 4
102+
InsertBraces: true
103+
InsertNewlineAtEOF: true
104+
SpaceBeforeInheritanceColon: true
105+
SpaceBeforeParens: Always
106+
SortIncludes: Never
107+
UseTab: ForContinuationAndIndentation
108+
TabWidth: 4
109+
WhitespaceSensitiveMacros:
110+
- COND_CODE_0
111+
- COND_CODE_1
112+
- IF_DISABLED
113+
- IF_ENABLED
114+
- LISTIFY
115+
- STRINGIFY
116+
- Z_STRINGIFY
117+
- DT_FOREACH_PROP_ELEM_SEP

.github/workflows/format_check.yml

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

0 commit comments

Comments
 (0)