From 5d9e918d5d0e4ead16c93b98224134ce16d904ec Mon Sep 17 00:00:00 2001 From: tangxifan Date: Thu, 6 Oct 2022 18:26:06 -0700 Subject: [PATCH] [ci] enable check C/C++ format on CI --- .../workflows/install_dependencies_build.sh | 3 +- dev/check-format.sh | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 dev/check-format.sh diff --git a/.github/workflows/install_dependencies_build.sh b/.github/workflows/install_dependencies_build.sh index 2f7809e97..a9068e340 100755 --- a/.github/workflows/install_dependencies_build.sh +++ b/.github/workflows/install_dependencies_build.sh @@ -58,4 +58,5 @@ sudo apt-get install -y \ clang-6.0 \ clang-7 \ clang-8 \ - clang-10 + clang-10 \ + clang-format-10 diff --git a/dev/check-format.sh b/dev/check-format.sh new file mode 100755 index 000000000..e8d970926 --- /dev/null +++ b/dev/check-format.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +clean=$(git status -s -uno | wc -l) #Short ignore untracked + +if [ $clean -ne 0 ]; then + echo "Current working tree was not clean! This tool only works on clean checkouts" + exit 2 +else + echo "Code Formatting Check" + echo "=====================" + make format"$1" > /dev/null 2>&1 + + valid_format=$(git diff | wc -l) + + if [ $valid_format -ne 0 ]; then + echo "FAILED" + echo "" + echo "You *must* make the following changes to match the formatting style" + echo "-------------------------------------------------------------------" + echo "" + + git diff + + echo "" + echo "Run 'make format$1' to apply these changes" + + git reset --hard > /dev/null + exit 1 + else + echo "OK" + fi +fi +exit 0