Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Check clang-format on changed PR source files

Rodney36b5cd393658
diff --git a/.github/workflows/workflow_clang_format.yml b/.github/workflows/workflow_clang_format.yml
new file mode 100644
index 000000000..adad701b0
--- /dev/null
+++ b/.github/workflows/workflow_clang_format.yml
@@ -0,0 +1,63 @@
+name: clang-format Check
+
+on:
+ pull_request:
+ paths:
+ - "toonz/sources/**/*.c"
+ - "toonz/sources/**/*.cc"
+ - "toonz/sources/**/*.cpp"
+ - "toonz/sources/**/*.cxx"
+ - "toonz/sources/**/*.h"
+ - "toonz/sources/**/*.hh"
+ - "toonz/sources/**/*.hpp"
+ - "toonz/sources/**/*.hxx"
+ - "toonz/sources/.clang-format"
+ - ".github/workflows/workflow_clang_format.yml"
+
+permissions:
+ contents: read
+
+jobs:
+ formatting-check:
+ name: Formatting Check
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+ ref: ${{ github.event.pull_request.head.sha }}
+
+ - name: Install clang-format
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y clang-format-14
+
+ - name: Check formatting of changed C/C++ files
+ env:
+ BASE_SHA: ${{ github.event.pull_request.base.sha }}
+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}
+ shell: bash
+ run: |
+ set -euo pipefail
+
+ files=()
+ while IFS= read -r -d '' file; do
+ case "$file" in
+ toonz/sources/*.c|toonz/sources/*.cc|toonz/sources/*.cpp|toonz/sources/*.cxx|\
+ toonz/sources/*.h|toonz/sources/*.hh|toonz/sources/*.hpp|toonz/sources/*.hxx)
+ files+=("$file")
+ ;;
+ esac
+ done < <(
+ git diff --name-only --diff-filter=ACMR -z \
+ "$BASE_SHA" "$HEAD_SHA"
+ )
+
+ if (( ${#files[@]} == 0 )); then
+ echo "No changed C/C++ files to check."
+ exit 0
+ fi
+
+ printf 'Checking %s\n' "${files[@]}"
+ clang-format-14 --dry-run --Werror -style=file "${files[@]}"