diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..f9d09e3e0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,15 @@ +--- +# We'll use defaults from the LLVM style, but with 4 columns indentation. +BasedOnStyle: LLVM +IndentWidth: 4 +--- +Language: Cpp +Standard: c++11 +Cpp11BracedListStyle: true +# Force pointers to the type for C++. +DerivePointerAlignment: false +PointerAlignment: Left +--- +Language: Proto +# Don't format .proto files. +DisableFormat: true diff --git a/.clang-format-ignore b/.clang-format-ignore new file mode 100644 index 000000000..c18f65b4b --- /dev/null +++ b/.clang-format-ignore @@ -0,0 +1,2 @@ +thirdparty/* +thirdparty_unman/* diff --git a/.github/workflows/check_clang_format_on_pr.yml b/.github/workflows/check_clang_format_on_pr.yml new file mode 100644 index 000000000..1f17d26fc --- /dev/null +++ b/.github/workflows/check_clang_format_on_pr.yml @@ -0,0 +1,44 @@ +name: Check Style in Code + +on: [pull_request] + +jobs: + clang-format: + name: Check sources by clang-format for added/changed files in PR + runs-on: ubuntu-latest + steps: + - name: Install LLVM and Clang + uses: KyleMayes/install-llvm-action@v2 + with: + version: "18.1.8" + + - name: Install parallel for work with check many files + run: | + sudo apt-get update + sudo apt-get install parallel -y + + - name: Checkout repository code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # for work tj-actions/changed-files + persist-credentials: false # for work tj-actions/changed-files + + - name: Get C/C++/Protobuf source files that have added/changed + id: changed-files + uses: tj-actions/changed-files@v45 + with: + files: '**/*.{h,H,hpp,hh,h++,hxx,c,C,cpp,cc,c++,cxx,ino,pde,cu,proto}' + files_ignore: 'thirdparty*/**/*.{h,H,hpp,hh,h++,hxx,c,C,cpp,cc,c++,cxx,ino,pde,cu,proto}' + + - name: List added/changed C/C++/Protobuf source file(s) for check + if: steps.changed-files.outputs.any_changed == 'true' + run: | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo "$file was changed" + done + + - name: Check added/changed C/C++/Protobuf source file(s) by clang-format + if: steps.changed-files.outputs.any_changed == 'true' + run: | + parallel clang-format --style=file --Werror --dry-run --verbose ::: \ + ${{ steps.changed-files.outputs.all_changed_files }}