From 4fd01921e4fa09e06fc6f0cbc4098b0a6a7befed Mon Sep 17 00:00:00 2001 From: Andrew Shkrob Date: Sat, 11 Jan 2025 17:03:46 +0100 Subject: [PATCH] [CI] Add cpp codestyle check Signed-off-by: Andrew Shkrob --- .github/workflows/cpp-code-check.yaml | 47 +++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/cpp-code-check.yaml diff --git a/.github/workflows/cpp-code-check.yaml b/.github/workflows/cpp-code-check.yaml new file mode 100644 index 0000000000..ab45157379 --- /dev/null +++ b/.github/workflows/cpp-code-check.yaml @@ -0,0 +1,47 @@ +name: Cpp code check +on: + pull_request: + paths: + - .github/workflows/cpp-code-check.yaml + - .clang-format + - '**/*.c' + - '**/*.cpp' + - '**/*.h' + - '**/*.hpp' + - '**/*.m' + - '**/*.mm' + - '!3party/**' + +jobs: + clang-format-check: + name: Clang-format check + runs-on: ubuntu-24.04 + steps: + - name: Calculate PR fetch depth + env: + COMMITS_COUNT: ${{ github.event.pull_request.commits }} + run: echo "PR_FETCH_DEPTH=$(($COMMITS_COUNT + 1))" >> "${GITHUB_ENV}" + + - name: Checkout PR branch and all PR commits + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} + fetch-depth: ${{ env.PR_FETCH_DEPTH }} + + - name: Install clang-format tool + run: sudo apt install -y clang-format + + - name: Check codestyle + env: + COMMITS_COUNT: ${{ github.event.pull_request.commits }} + run: | + git clang-format HEAD~$COMMITS_COUNT HEAD --extensions 'c,cpp,h,hpp,m,mm' --diff >> clang-format.diff + + - name: Show clang-format diff + if: failure() + run: | + echo "Some files are not formatted correctly:" + echo "::group::clang-format.diff" + cat clang-format.diff + echo "::endgroup::" -- 2.45.3