Skip to content

Clang Format Check

Clang Format Check #10

name: Clang Format Check
on:
workflow_run:
workflows: ["Compile"]
types:
- completed
push:
branches: [ "main" ]
paths:
- '**/*.cpp'
- '**/*.h'
- '**/*.c'
- '**/*.hpp'
pull_request:
branches: [ "main" ]
paths:
- '**/*.cpp'
- '**/*.h'
- '**/*.c'
- '**/*.hpp'
permissions:
contents: write
jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Install clang-format
run: sudo apt-get install clang-format
- name: Run clang-format
run: |
find . -name '*.cpp' -o -name '*.h' -o -name '*.c' -o -name '*.hpp' | xargs clang-format -i
- name: Check for formatting issues
run: git diff --exit-code
id: format-check
continue-on-error: true
- name: Commit and push changes
if: steps.format-check.outcome == 'failure'
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git add .
git commit -m 'Auto format code with clang-format'
git push origin ${{ github.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}