Skip to content

Commit fee8748

Browse files
committed
Cleanup .travis.yml
* Use matrix to run clang-format / doxygen rather than if condition in script.
1 parent 98653c9 commit fee8748

1 file changed

Lines changed: 49 additions & 51 deletions

File tree

.travis.yml

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,52 @@ matrix:
99
include:
1010
- os: linux
1111
dist: xenial
12-
env: TOOL=clang-format
12+
env: JOB=clang-format
1313
addons:
1414
apt:
1515
sources:
1616
- llvm-toolchain-xenial-8
1717
packages:
1818
- clang-format-8
1919
compiler: clang
20+
script: |
21+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
22+
BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH)
23+
echo "Running clang-format-8 against branch $TRAVIS_BRANCH, with hash $BASE_COMMIT"
24+
COMMIT_FILES=$(git diff --name-only $BASE_COMMIT | grep -ivE 'LinkDef|Utilities/PCG/')
25+
RESULT_OUTPUT="$(git-clang-format-8 --commit $BASE_COMMIT --diff --binary `which clang-format-8` $COMMIT_FILES)"
26+
27+
for x in $COMMIT_FILES; do
28+
case $x in
29+
*.h|*.cxx)
30+
# We remove the header from the diff as it contains +++ then
31+
# we only select the added lines to check for the long ones.
32+
# We do not need to check for the lines which have been removed
33+
# and we do not want to check for the lines which were not changed
34+
# to avoid extra work.
35+
# 120 characters are allowed, meaning the error should start with 122,
36+
# to allow for the starting + at the end of the line.
37+
git diff $x | tail -n +5 | grep -e '^+' | grep '.\{122,\}' && { echo "Line longer than 120 chars in $x." && exit 1; } || true ;;
38+
*.hxx|*.cc|*.hpp) echo "$x uses non-allowed extension." && exit 1 ;;
39+
*) ;;
40+
esac
41+
done
42+
43+
if [ "$RESULT_OUTPUT" == "no modified files to format" ] \
44+
|| [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ] ; then
45+
echo "clang-format passed."
46+
exit 0
47+
else
48+
echo "clang-format failed."
49+
echo "To reproduce it locally please run"
50+
echo -e "\tgit checkout $TRAVIS_BRANCH"
51+
echo -e "\tgit-clang-format --commit $BASE_COMMIT --diff --binary $(which clang-format)"
52+
echo "$RESULT_OUTPUT"
53+
exit 1
54+
fi
55+
fi
2056
- os: linux
21-
env: TOOL=doxygen
57+
env: JOB=doxygen
2258
addons:
2359
apt:
2460
packages:
@@ -28,59 +64,21 @@ matrix:
2864
- doxygen-gui
2965
- graphviz
3066
- cmake
67+
script: |
68+
cat > CMakeLists.txt <<\EOF
69+
add_subdirectory(doc)
70+
EOF
71+
# This is required because of differences between doxygen and github
72+
# markdown syntax for code blocks. The committed code should use
73+
# the github flavour and we generate the doxygen one on the fly.
74+
git grep -l '^```[a-zA-Z]' | xargs sed -i .old -e 's|```\([a-zA-Z][a-zA-Z]*\)|\n```{.\1}\n|g;s|[.]bash|.sh|g;s|```|~~~~~~~|g'
75+
find . -name "*.old" -delete
76+
cmake .
77+
make doc
3178
deploy:
3279
provider: pages
3380
skip_cleanup: true
3481
github_token: $GITHUB_API_TOKEN # Set in travis-ci.org dashboard
3582
local_dir: doc/html
3683
on:
3784
branch: dev
38-
script: |
39-
if [[ $TOOL == "doxygen" ]]; then
40-
cat > CMakeLists.txt <<\EOF
41-
add_subdirectory(doc)
42-
EOF
43-
# This is required because of differences between doxygen and github
44-
# markdown syntax for code blocks. The committed code should use
45-
# the github flavour and we generate the doxygen one on the fly.
46-
git grep -l '^```[a-zA-Z]' | xargs sed -i .old -e 's|```\([a-zA-Z][a-zA-Z]*\)|\n```{.\1}\n|g;s|[.]bash|.sh|g;s|```|~~~~~~~|g'
47-
find . -name "*.old" -delete
48-
cmake .
49-
make doc
50-
elif [[ $TOOL == "clang-format" ]]; then
51-
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
52-
BASE_COMMIT=$(git rev-parse $TRAVIS_BRANCH)
53-
echo "Running clang-format-8 against branch $TRAVIS_BRANCH, with hash $BASE_COMMIT"
54-
COMMIT_FILES=$(git diff --name-only $BASE_COMMIT | grep -ivE 'LinkDef|Utilities/PCG/')
55-
RESULT_OUTPUT="$(git-clang-format-8 --commit $BASE_COMMIT --diff --binary `which clang-format-8` $COMMIT_FILES)"
56-
57-
for x in $COMMIT_FILES; do
58-
case $x in
59-
*.h|*.cxx)
60-
# We remove the header from the diff as it contains +++ then
61-
# we only select the added lines to check for the long ones.
62-
# We do not need to check for the lines which have been removed
63-
# and we do not want to check for the lines which were not changed
64-
# to avoid extra work.
65-
# 120 characters are allowed, meaning the error should start with 122,
66-
# to allow for the starting + at the end of the line.
67-
git diff $x | tail -n +5 | grep -e '^+' | grep '.\{122,\}' && { echo "Line longer than 120 chars in $x." && exit 1; } || true ;;
68-
*.hxx|*.cc|*.hpp) echo "$x uses non-allowed extension." && exit 1 ;;
69-
*) ;;
70-
esac
71-
done
72-
73-
if [ "$RESULT_OUTPUT" == "no modified files to format" ] \
74-
|| [ "$RESULT_OUTPUT" == "clang-format did not modify any files" ] ; then
75-
echo "clang-format passed."
76-
exit 0
77-
else
78-
echo "clang-format failed."
79-
echo "To reproduce it locally please run"
80-
echo -e "\tgit checkout $TRAVIS_BRANCH"
81-
echo -e "\tgit-clang-format --commit $BASE_COMMIT --diff --binary $(which clang-format)"
82-
echo "$RESULT_OUTPUT"
83-
exit 1
84-
fi
85-
fi
86-
fi

0 commit comments

Comments
 (0)