Skip to content

Commit

Permalink
Add clang-format github action
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbopet committed Sep 24, 2023
1 parent 6baa37b commit 569263b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Check code format

on: [push, pull_request]

jobs:
build:
name: Check with clang-format
runs-on: ubuntu-latest
steps:
- name: Get Ripes
uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 2
- name: clang-format
run: |
# Run clang-format
CHANGED_FILES=`git diff --name-only -r HEAD~ | grep -E '.(c|cpp|h|hpp)$' | xargs`
echo "Changed files: $CHANGED_FILES"
[ -z "$CHANGED_FILES" ] && exit 0
clang-format -i $CHANGED_FILES
git diff > clang-format.patch
if [ -s clang-format.patch ]; then
echo "Clang-format found formatting problems in the following files. See diff in the clang-format.patch artifact."
git diff --name-only
exit 1
fi
echo "Clang-format found no formatting problems"
exit 0
- name: Upload clang-format patch
uses: actions/upload-artifact@v2
if: ${{ failure() }}
# Unfortunately, artifact uploads are always zips :(
with:
name: clang-format-patch
path: clang-format.patch
- name: clang-format patch display
if: ${{ failure() }}
run: |
# Display patch
cat clang-format.patch

0 comments on commit 569263b

Please sign in to comment.