Skip to content

Commit

Permalink
Clang format in the CI
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Mazur <mateusz.mazur@e.email>
  • Loading branch information
Mazurel committed Nov 11, 2024
1 parent 96661a0 commit ca4eb0f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: true
Enabled: true
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
Expand All @@ -26,7 +26,7 @@ AlignConsecutiveDeclarations:
AlignFunctionPointers: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Clang formatting checker

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest
container:
image: silkeh/clang # https://hub.docker.com/r/silkeh/clang
env:
DRY: "TRUE"

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Checking formatting
run: DRY=TRUE bash reformat-all.sh
15 changes: 13 additions & 2 deletions reformat-all.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#!/bin/sh
#!/usr/bin/env bash

find . -name '*.cpp' -o -name '*.hpp' | xargs clang-format -i -style=file
ALL_FORMATABLE_FILES=$(find src include tests example -name '*.cpp' -o -name '*.hpp')
CLANG_FORMAT_ARGS="-style=file"

echo "*** Modbus Clang Format Wrapper **"
clang-format --version

if [[ "$DRY" = "TRUE" ]]; then
diff_count=`clang-format --dry-run $CLANG_FORMAT_ARGS $ALL_FORMATABLE_FILES 2>&1 | wc -l`
exit $(($diff_count > 0))
else
clang-format -i --verbose $CLANG_FORMAT_ARGS $ALL_FORMATABLE_FILES
fi

0 comments on commit ca4eb0f

Please sign in to comment.