diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml index 89e1076ef..4da722258 100644 --- a/.github/workflows/clang-format-check.yml +++ b/.github/workflows/clang-format-check.yml @@ -26,3 +26,12 @@ jobs: - name: Check Clang-Format on Diff run: | ./clang-format-diff.sh ${{ github.base_ref }} ${{ github.ref }} + + - name: Apply Clang-Format locally + run: | + ./clang-format-apply.sh ${{ github.base_ref }} ${{ github.ref }} + + - name: Suggest changes + uses: parkerbxyz/suggest-changes@v1 + with: + comment: 'Please make the changes suggested by clang-format' diff --git a/clang-format-apply.sh b/clang-format-apply.sh new file mode 100644 index 000000000..35574237d --- /dev/null +++ b/clang-format-apply.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +BASE_BRANCH=$1 +CURRENT_BRANCH=$2 + +# Save unified diff with 0 context +git diff -U0 --name-only $BASE_BRANCH...$CURRENT_BRANCH > changes.diff + +# Apply clang-format on diff +FORMAT_DIFF=$(clang-format -i -style=file changes.diff)