diff options
author | Heejin Ahn <aheejin@gmail.com> | 2021-08-05 21:32:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-05 21:32:19 -0700 |
commit | a92466a4dd1f5c2b8cb2fa05d3afa7e1f34e80af (patch) | |
tree | 03b02766d9a1984398c789538f17a5d03609ace2 /scripts/clang-format-diff.sh | |
parent | afd5a5e8eb3bb315c7a50e22617c5529ba400c8c (diff) | |
download | wabt-a92466a4dd1f5c2b8cb2fa05d3afa7e1f34e80af.tar.gz wabt-a92466a4dd1f5c2b8cb2fa05d3afa7e1f34e80af.tar.bz2 wabt-a92466a4dd1f5c2b8cb2fa05d3afa7e1f34e80af.zip |
Add clang-format check to CI (#1683)
This adds clang-format check to the CI. This only checks the diff so it
doesn't affect the other parts of the codebase. Also generated files in
src/prebuilt/ directories are excluded from the check. A new
src/prebuilt/.clang-format is added to disable the check in the
directory.
scripts/clang-format-diff.sh is copied from the same file we are using in
Binaryen.
Diffstat (limited to 'scripts/clang-format-diff.sh')
-rwxr-xr-x | scripts/clang-format-diff.sh | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/scripts/clang-format-diff.sh b/scripts/clang-format-diff.sh new file mode 100755 index 00000000..01a813f2 --- /dev/null +++ b/scripts/clang-format-diff.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -o errexit +set -o pipefail + +if [ -n "$1" ]; then + BRANCH="$1" +elif [ -n "$GITHUB_BASE_REF" ]; then + BRANCH="origin/$GITHUB_BASE_REF" +else + BRANCH="@{upstream}" +fi + +MERGE_BASE=$(git merge-base $BRANCH HEAD) +FORMAT_MSG=$(git clang-format $MERGE_BASE -q --diff -- src/) +if [ -n "$FORMAT_MSG" -a "$FORMAT_MSG" != "no modified files to format" ] +then + echo "Please run git clang-format before committing, or apply this diff:" + echo + # Run git clang-format again, this time without capruting stdout. This way + # clang-format format the message nicely and add color. + git clang-format $MERGE_BASE -q --diff -- src/ + exit 1 +fi |