diff --git a/.travis.yml b/.travis.yml index e63b33157fae37cafde9df01599afda83d197895..16e53174da12fbe41f64bfd63d8ce3837021029f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,8 @@ install: - tar -xf cmake-3.7.1-Linux-x86_64.tar.gz - export PATH="${PWD}/cmake-3.7.1-Linux-x86_64/bin:${PATH}" - pip install --user flake8 +env: + - BUILD_MATRIX_ENTRY=format script: - - cd ${TRAVIS_BUILD_DIR} - - scripts/travis/run-clang-format.sh - - ~/.local/bin/flake8 --config=flake8.cfg . + - ${TRAVIS_BUILD_DIR}/scripts/travis/run.sh diff --git a/scripts/travis/run-clang-format.sh b/scripts/travis/run-clang-format.sh deleted file mode 100755 index 2cf0cfef5e988557cf40eda7b9150cec75c8e62a..0000000000000000000000000000000000000000 --- a/scripts/travis/run-clang-format.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -if [ -z "${TRAVIS_PULL_REQUEST_BRANCH}" ] -then - echo "This is only designed to run on Pull Requests" - exit 1 -else - COMMIT_RANGE="${TRAVIS_COMMIT_RANGE/.../ }" -fi - -# Run clang-format -DIFF="$(${TRAVIS_BUILD_DIR}/scripts/developer/git/git-clang-format --diff ${COMMIT_RANGE})" -if [ "${DIFF}" != "no modified files to format" ] -then - echo "clang-format:" - echo " Code format checks failed." - echo " Please run clang-format (or git clang-format) on your changes" - echo " before committing." - echo " The following changes are suggested:" - echo "${DIFF}" - exit 1 -fi - -exit 0 diff --git a/scripts/travis/run-format.sh b/scripts/travis/run-format.sh new file mode 100755 index 0000000000000000000000000000000000000000..7ba5997382c3a5f7c4cf33019211dde34b9f1f8f --- /dev/null +++ b/scripts/travis/run-format.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +if [ -z "${SOURCE_DIR}" ] +then + echo "Error: SOURCE_DIR is empty or undefined" + exit 1 +fi +if [ -z "${COMMIT_RANGE}" ] +then + echo "Error: COMMIT_RANGE is empty or undefined" + exit 1 +fi + +cd ${SOURCE_DIR} + +# Check C and C++ code with clang-format +DIFF="$(./scripts/developer/git/git-clang-format --diff ${COMMIT_RANGE})" +if [ "${DIFF}" != "no modified files to format" ] +then + echo "clang-format:" + echo " Code format checks failed." + echo " Please run clang-format (or git clang-format) on your changes" + echo " before committing." + echo " The following changes are suggested:" + echo "${DIFF}" + exit 1 +fi + +# Check python code with flake8 +if ! ~/.local/bin/flake8 --config=flake8.cfg . +then + exit 3 +fi + +exit 0 diff --git a/scripts/travis/run.sh b/scripts/travis/run.sh new file mode 100755 index 0000000000000000000000000000000000000000..5d013823605594e85907ee61995c4cf9706bd882 --- /dev/null +++ b/scripts/travis/run.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + + +export SOURCE_DIR=${TRAVIS_BUILD_DIR} +export BUILD_DIR=$(readlink -f ${SOURCE_DIR}/..) +export COMMIT_RANGE="${TRAVIS_COMMIT_RANGE/.../ }" + +case ${BUILD_MATRIX_ENTRY} in + format) + echo "Running formatting tests" + if ! ${SOURCE_DIR}/scripts/travis/run-format.sh; then + exit 1; + fi + ;; + *) + echo "Error: BUILD_MATRIX_ENTRY is undefined or set to an unknown value" + exit 1; + ;; +esac