Skip to content

Commit a3ef6ef

Browse files
CI: Add clang-format checker
You can run docker run -u $UID -v $PWD:$PWD ghcr.io/tpm2-software/ubuntu-24.04 clang-format -i $(find -name '*.h' -or -name '*.c' | xargs realpath) for checking. Signed-off-by: Andreas Fuchs <andreas.fuchs@infineon.com>
1 parent d57408e commit a3ef6ef

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

.github/workflows/clang-format.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Infineon Technologies AG
2+
#
3+
# SPDX-License-Identifier: BSD-2-Clause
4+
5+
name: Clang Format Checker
6+
on:
7+
[push, pull_request]
8+
jobs:
9+
clang-format-checking:
10+
runs-on: ubuntu-latest
11+
container:
12+
image: ghcr.io/tpm2-software/ubuntu-24.04
13+
steps:
14+
- name: Check out repository
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 1
18+
- name: Run clang-format
19+
run: clang-format -i $(find -name '*.h' -or -name '*.c' | xargs realpath)
20+
- name: Check for diffs
21+
run: |
22+
git config --global --add safe.directory $PWD
23+
git diff --exit-code && echo "No formatting issues found."
24+
- name: failure
25+
if: ${{ failure() }}
26+
run: |
27+
echo "Clang format check failed. Please run clang-format on your code or see the diff in the step above."
28+
echo "docker run -u $UID -v $PWD:$PWD ghcr.io/tpm2-software/ubuntu-24.04 clang-format -i $(find -name '*.h' -or -name '*.c' | xargs realpath)"

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ full text of the DCO is here: https://developercertificate.org/. Contributors
4444
must add a 'Signed-off-by' line to their commits. This indicates the
4545
submitters acceptance of the DCO.
4646

47+
Please note that we now require REUSE and clang-format to also pass on PRs.
48+
You may run
49+
```sh
50+
docker run -u $UID -v $PWD:$PWD ghcr.io/tpm2-software/ubuntu-24.04 clang-format -i $(find -name '*.h' -or -name '*.c' | xargs realpath)
51+
```
52+
before submitting in order to align with our format requirements.
53+
4754
## Guideline for merging changes
4855

4956
Pull Requests MUST be assigned to an upcoming release tag. If a release milestone does

doc/coding_standard_c.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ check the surrounding code and imitate its style [1].
99
For simplicity, we use clang-format for all files (also as part of the CI).
1010
Thus before commiting any code, we recommend you run
1111
```sh
12-
docker run -u 1000 -v $PWD:$PWD xianpengshen/clang-tools:17 clang-format -i $(find -name '*.c' | xargs realpath)
13-
docker run -u 1000 -v $PWD:$PWD xianpengshen/clang-tools:17 clang-format -i $(find -name '*.h' | xargs realpath)
12+
docker run -u $UID -v $PWD:$PWD ghcr.io/tpm2-software/ubuntu-24.04 clang-format -i $(find -name '*.h' -or -name '*.c' | xargs realpath)
1413
```
1514
This ensures that the code will not break during your pull request.
1615

0 commit comments

Comments
 (0)