Last active
October 25, 2019 11:21
-
-
Save ufna/84a47922e2b8dc7bd1eff7c92083ec3f to your computer and use it in GitHub Desktop.
clang-format CI check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
FIND=/usr/bin/find | |
GIT=/usr/bin/git | |
XARGS=/usr/bin/xargs | |
CLANG_FORMAT=/usr/bin/clang-format-6.0 | |
DIRECTORY=%system.target.directory% | |
if [ "$DIRECTORY" == "" ]; then | |
DIRECTORY="Source" | |
fi | |
if [ ! -d $DIRECTORY/ ]; then | |
echo "Happily skipping $DIRECTORY: nothing to check means no errors." 1>&2 | |
exit | |
fi | |
echo "Go to $DIRECTORY/" 1>&2 | |
cd "$DIRECTORY/" | |
$FIND . -type f -name '*.cpp' -print0 | $XARGS -0 $CLANG_FORMAT -i | |
$FIND . -type f -name '*.h' -print0 | $XARGS -0 $CLANG_FORMAT -i | |
# only local dir | |
if ! git diff --exit-code . 1>&2; then | |
REP=`mktemp` | |
echo -n '{"text":"clang-format check\n' >> $REP | |
( git describe --all --long ; git status --short . ) | sed -e 's/$/\\n/' | tr -d '\n' >> $REP | |
echo '"}' >> $REP | |
echo -n "Report to slack: " | |
curl \ | |
--silent \ | |
-X POST \ | |
-H 'Content-type: application/json' \ | |
--data @$REP \ | |
%system.slack.webhook% | |
rm $REP | |
false | |
fi | |
echo "No changes found" 1>&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment