Clang Format Check #14
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
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 }} |