Skip to content

ci(clang-format): add clang-format check workflow #1

ci(clang-format): add clang-format check workflow

ci(clang-format): add clang-format check workflow #1

name: Clang Format Check
on:
pull_request:
push:
branches:
- main
jobs:
clang-format-check:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code from the repository
- name: Checkout the code
uses: actions/checkout@v3
# Step 2: Install clang-format
- name: Install clang-format
run: sudo apt-get install -y clang-format
# Step 3: Find .c and .h files that need formatting
- name: Check if files are properly formatted
run: |
FILES_TO_CHECK=$(find . -name "*.c" -o -name "*.h")
for file in $FILES_TO_CHECK; do
clang-format --style=file -i $file
done
# Step 4: Check if files match .clang-format style
- name: Validate formatting
run: |
FILES_TO_CHECK=$(find . -name "*.c" -o -name "*.h")
for file in $FILES_TO_CHECK; do
if ! diff -u $file <(clang-format --style=file $file); then
echo "Formatting issues in $file"
exit 1
fi
done