From eb732e11b907548e5f3cac79de01f938f5cc787b Mon Sep 17 00:00:00 2001 From: Ping Xie Date: Sun, 26 May 2024 23:49:31 -0700 Subject: [PATCH] Update clang-format action Signed-off-by: Ping Xie --- .github/workflows/clang-format.yml | 12 ++++++++---- src/.clang-format-ignore | 1 - src/unit/test_files.h | 1 + utils/generate-unit-test-header.py | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index e5135c3c3e..5b348cf971 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -24,12 +24,16 @@ jobs: # Run clang-format and capture the diff cd src clang-format -i **/*.c **/*.h - git diff --exit-code + # Capture the diff output + DIFF=$(git diff) + if [ ! -z "$DIFF" ]; then + echo "::set-output name=diff::$DIFF" + fi shell: bash - name: Check for formatting changes - if: ${{ failure() }} + if: steps.clang-format.outputs.diff run: | - echo "Code is not formatted correctly." + echo "Code is not formatted correctly. Here is the diff:" + echo "${{ steps.clang-format.outputs.diff }}" exit 1 - diff --git a/src/.clang-format-ignore b/src/.clang-format-ignore index 894187c2fe..b5519ddfc4 100644 --- a/src/.clang-format-ignore +++ b/src/.clang-format-ignore @@ -14,4 +14,3 @@ sha1.* sha256.* siphash.c strl.c -unit/test_files.h diff --git a/src/unit/test_files.h b/src/unit/test_files.h index 6af8f4c380..16c88eb2d9 100644 --- a/src/unit/test_files.h +++ b/src/unit/test_files.h @@ -1,4 +1,5 @@ /* Do not modify this file, it's automatically generated from utils/generate-unit-test-header.py */ +/* clang-format off */ typedef int unitTestProc(int argc, char **argv, int flags); typedef struct unitTest { diff --git a/utils/generate-unit-test-header.py b/utils/generate-unit-test-header.py index 00cd852f2d..1b2619e40f 100755 --- a/utils/generate-unit-test-header.py +++ b/utils/generate-unit-test-header.py @@ -26,6 +26,7 @@ test_suites.append({'file': file, 'tests': tests}) test_suites.sort(key=lambda test_suite: test_suite['file']) output.write("""/* Do not modify this file, it's automatically generated from utils/generate-unit-test-header.py */ +/* clang-format off */ typedef int unitTestProc(int argc, char **argv, int flags); typedef struct unitTest { @@ -56,4 +57,4 @@ """) for test_suite in test_suites: output.write(' {{"{0}", __{1}}},\n'.format(test_suite['file'], test_suite['file'].replace('.c', '_c'))) - output.write('};\n') \ No newline at end of file + output.write('};\n')