Skip to content

Commit a96bc0f

Browse files
authored
Add clang-format to travis (#45)
1 parent 1c79da3 commit a96bc0f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

.travis.yml

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ matrix:
55
include:
66
- os: osx
77
osx_image: xcode9.2
8-
env:
8+
env: TOOL=test
99
- os: linux
10-
env:
10+
env: TOOL=test
11+
- os: linux
12+
env: TOOL=clang-format
13+
addons:
14+
apt:
15+
sources: *sources
16+
packages: ['clang-format-3.9']
17+
compiler: clang
1118
- os: linux
1219
env: TOOL=doxygen
1320
addons:
@@ -42,8 +49,22 @@ before_script:
4249
- mkdir build; cd build
4350
script:
4451
- cmake ..
45-
- if [[ $TOOL != "doxygen" ]]; then make -j; fi
46-
- if [[ $TOOL != "doxygen" ]]; then make test; fi
52+
- if [[ $TOOL == "test" ]]; then make -j; fi
53+
- if [[ $TOOL == "test" ]]; then make test; fi
4754
- if [[ $TOOL == "doxygen" ]]; then make doc; fi
55+
- if [[ $TOOL == "clang-format" ]] && [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
56+
cd $TRAVIS_BUILD_DIR;
57+
BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH);
58+
COMMIT_FILES=$(git diff --name-only $BASE_COMMIT | grep -i -v LinkDef);
59+
RESULT_OUTPUT="$(git-clang-format-3.9 --commit $BASE_COMMIT --diff --binary `which clang-format-3.9` $COMMIT_FILES)";
60+
if [ "$RESULT_OUTPUT" == "no modified files to format" ] || [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ]; then
61+
echo "clang-format passed";
62+
exit 0;
63+
else
64+
echo "clang-format failed.";
65+
echo "$RESULT_OUTPUT";
66+
exit 1;
67+
fi
68+
fi
4869
notifications:
4970
email: false

0 commit comments

Comments
 (0)