Skip to content

Clang format in the CI #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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