Skip to content

Commit

Permalink
Add format checker action
Browse files Browse the repository at this point in the history
  • Loading branch information
vstumpf committed Jan 19, 2024
1 parent 5f03d2d commit 5dc241d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Check format of code

on:
pull_request:
paths:
# Always trigger all Github Actions if an action or something CI related was changed
- ".github/workflows/**"
- "tools/ci/**"
- ".clang-format"
# This workflow should run when a file in a source directory has been modified.
- "src/**"

jobs:
clang-format:
# Github Actions checks for '[ci skip]', '[skip ci]', '[no ci]', '[skip actions]', or '[actions skip]' but not a hyphenated version.
# It's a catch-all incase a Pull Request has been opened and someone is on auto-pilot.
if: "!contains(github.event.head_commit.message, 'ci-skip')"
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Check format
run: ./tools/ci/check-format.sh
20 changes: 20 additions & 0 deletions tools/ci/check-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

SHOULD_EXIT=0

# only check files in common for now
for FILE in $(ls src/common/*.hpp src/common/*.cpp)
do
CHANGES=$(diff -u <(cat $FILE) <(clang-format $FILE))
if [ -n "$CHANGES" ]; then
echo "File $FILE is not formatted correctly"
echo "$CHANGES"
SHOULD_EXIT=1
fi
done

if [ $SHOULD_EXIT -eq 1 ]; then
echo "Some files are not formatted correctly, please run clang-format"
exit 1
fi
echo "All files are formatted correctly"

0 comments on commit 5dc241d

Please sign in to comment.