Skip to content

Commit b26042b

Browse files
authored
Add github worflow for clang-format checking (#221)
Make sure PRs pass clang-format check before merging.
1 parent ece5a38 commit b26042b

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

.github/workflows/clang-format.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the License); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
name: Check clang-format
18+
19+
on:
20+
pull_request:
21+
paths:
22+
- ".clang-format"
23+
- ".github/workflows/clang-format.yml"
24+
- "Include/**"
25+
- "Source/**"
26+
- "Tests/UnitTest/Corstone-300/**"
27+
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ github.ref }}
30+
cancel-in-progress: true
31+
32+
jobs:
33+
clang_format:
34+
name: Check clang-format
35+
runs-on: ubuntu-24.04
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v6
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Install clang-format
43+
run: |
44+
sudo apt-get update
45+
sudo apt-get install --yes clang-format-18
46+
47+
- name: Check changed source files
48+
shell: bash
49+
run: |
50+
mapfile -t files < <(
51+
git diff --name-only --diff-filter=d \
52+
"${{ github.event.pull_request.base.sha }}" \
53+
"${{ github.event.pull_request.head.sha }}" \
54+
-- \
55+
Include \
56+
Source \
57+
Tests/UnitTest/Corstone-300 |
58+
grep -E '\.(c|cc|cpp|h|hpp)$' || true
59+
)
60+
61+
if [ "${#files[@]}" -eq 0 ]; then
62+
echo "No changed C/C++ source files to check."
63+
exit 0
64+
fi
65+
66+
clang-format-18 --dry-run --Werror "${files[@]}"

0 commit comments

Comments
 (0)