From ec8ccc7c2744fc635f863df0f32e54bf1579bbec Mon Sep 17 00:00:00 2001 From: quic-zhaoyuan <164289792+quic-zhaoyuan@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:39:21 +0800 Subject: [PATCH] Create action --- .github/workflows/cpp-code-style-checker.yml | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/cpp-code-style-checker.yml diff --git a/.github/workflows/cpp-code-style-checker.yml b/.github/workflows/cpp-code-style-checker.yml new file mode 100644 index 0000000..13443d5 --- /dev/null +++ b/.github/workflows/cpp-code-style-checker.yml @@ -0,0 +1,36 @@ +name: Cpp Code Style Checker + +on: [push, pull_request, workflow_dispatch] + +jobs: + cpp-code-style-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install clang-format + run: sudo apt install -y clang-format + + - name: Setup clang-format configuration + run: | + if [ ! -f ./.clang-format ]; then + echo "No .clang-format found, will use default configuration" + curl -o .clang-format https://raw.githubusercontent.com/quic-qrb-ros/.github/main/code-style-profiles/.clang-format + fi + + - name: Check code style + run: | + SRC=$(git ls-tree --full-tree -r HEAD | grep -e "\.\(c\|h\|hpp\|cpp\)\$" | cut -f 2) + + echo -e "Check source files: \n$SRC\n" + clang-format -style=file -i $SRC + + if ! git diff --exit-code; then + echo -e "\nCode does not match required style !!!" + echo "Please use clang-format to format your code." + exit 1 + else + echo "All files are properly formatted." + fi