-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Clang Format Check | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
format: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Fetch all history for all tags and branches | ||
|
||
- name: Install clang-format | ||
run: sudo apt-get install -y clang-format | ||
|
||
- name: Check code formatting | ||
run: | | ||
cd src | ||
# Find all C/C++ files, format them and check for differences | ||
find . -regex '.*\.\(cpp\|hpp\|c\|h\)' | while read file; do | ||
clang-format -style=file "$file" | diff -u "$file" - | ||
if [ $? -ne 0 ]; then | ||
echo "::error file=$file::File is not formatted correctly" | ||
FORMAT_STATUS=1 | ||
fi | ||
done | ||
# Fail the job if any files were not formatted correctly | ||
if [ $FORMAT_STATUS -ne 0 ]; then | ||
exit 1 | ||
fi |