Skip to content

Run clang-format in GitHub Actions #22

Run clang-format in GitHub Actions

Run clang-format in GitHub Actions #22

Workflow file for this run

name: Clang Format Check
on:
pull_request:
paths:
- 'Sources/**'
- 'Tests/**'
- 'Samples/Common/Sources/CrashTriggers/**'
- '.github/workflows/clang-format.yml'
- '.clang-format-ignore'
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install clang-format-18
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
sudo apt-get install -y clang-format-18
- name: Define directories
run: echo "DIRS='Sources Tests Samples/Common/Sources/CrashTriggers' " >> $GITHUB_ENV
- name: Check formatting
run: |
find $DIRS -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.m' | \
xargs -r clang-format-18 -style=file -n -Werror
- name: Generate formatting diff
if: failure()
run: |
find $DIRS -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.m' | \
xargs -r clang-format-18 -style=file -i
git diff > clang_format_diff.patch
- name: Upload formatting diff
if: failure()
uses: actions/upload-artifact@v4
with:
name: clang-format-diff
path: clang_format_diff.patch
- name: Suggest formatting fixes
if: failure()
run: |
echo "Formatting issues found. Please run clang-format-18 on your code."
echo "You can download the formatting diff from the artifacts of this workflow run."
echo "Apply the patch using: git apply clang_format_diff.patch"
echo "Note: Some files may be excluded from formatting based on .clang-format-ignore file."
exit 1