From e0790f677b6ef1ce8bd436b135657100393cdd39 Mon Sep 17 00:00:00 2001 From: GameTec_live Date: Tue, 2 Sep 2025 19:26:01 +0200 Subject: [PATCH] feat: clang formatter --- .clang-format | 5 +++++ .github/workflows/c-checks.yml | 35 +++++++++++++++++++++++++++++ .github/workflows/python-checks.yml | 1 + firmware/format.sh | 8 +++++++ 4 files changed, 49 insertions(+) create mode 100644 .clang-format create mode 100644 .github/workflows/c-checks.yml create mode 100644 firmware/format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..78fd828 --- /dev/null +++ b/.clang-format @@ -0,0 +1,5 @@ +BreakBeforeBinaryOperators: All +ColumnLimit: 120 +BasedOnStyle: Google +BreakBeforeBraces: Stroustrup +IndentWidth: 4 diff --git a/.github/workflows/c-checks.yml b/.github/workflows/c-checks.yml new file mode 100644 index 0000000..2338778 --- /dev/null +++ b/.github/workflows/c-checks.yml @@ -0,0 +1,35 @@ +name: clang-format Check +on: + pull_request: + paths: + - '**.c' + - '**.h' + - '**.cpp' + workflow_dispatch: + +jobs: + check-format: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install clang-format + run: sudo apt install -y clang-format + + - name: Get files and check format + run: | + exit_code=0 + while IFS= read -r -d '' f; do + if ! diff -u "$f" <(clang-format "$f"); then + echo "Formatting issue in $f" + exit_code=1 + fi + done < <(find . -type f \( -name '*.c' -o -name '*.h' \) ! -path './firmware/nrf52_sdk/*' ! -path './firmware/nrf52_sdk/**' -print0) + + if [ $exit_code -ne 0 ]; then + echo "Clang-format check failed." + exit 1 + else + echo "All files are properly formatted." + fi \ No newline at end of file diff --git a/.github/workflows/python-checks.yml b/.github/workflows/python-checks.yml index 0e2074e..c52ccc1 100644 --- a/.github/workflows/python-checks.yml +++ b/.github/workflows/python-checks.yml @@ -5,6 +5,7 @@ on: paths: - "software/**" - ".github/workflows/**" + - "**.py" workflow_dispatch: jobs: diff --git a/firmware/format.sh b/firmware/format.sh new file mode 100644 index 0000000..f098d71 --- /dev/null +++ b/firmware/format.sh @@ -0,0 +1,8 @@ +#!/bin/env bash + +# Make it a bit less prone to breaking +cd "$(dirname "$0")/.." || exit + +while IFS= read -r -d '' f; do + clang-format --verbose -i "$f" +done < <(find . -type f \( -name '*.c' -o -name '*.h' \) ! -path './firmware/nrf52_sdk/*' ! -path './firmware/nrf52_sdk/**' -print0) \ No newline at end of file