diff options
author | Joseph Herlant <aerostitch@users.noreply.github.com> | 2018-05-30 11:21:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-30 11:21:59 -0700 |
commit | b64d59d4574ff5ec16d5429d1b3e4f761f58b0f5 (patch) | |
tree | cbec55a1b8087f17e275f9fd49c46df922287731 | |
parent | 567a02aa949dfa34f7b2c2246c6eb6f8818fdf01 (diff) | |
download | navit-b64d59d4574ff5ec16d5429d1b3e4f761f58b0f5.tar.gz |
add:ci:Add sanity check script on circleci (#606)
* add:ci:Add sanity check script
* fix:ci:use setup_common_requirements.sh for installing pre-requisites
-rw-r--r-- | .circleci/config.yml | 35 | ||||
-rwxr-xr-x | scripts/ci_sanity_checks.sh | 38 | ||||
-rw-r--r-- | scripts/setup_common_requirements.sh | 2 |
3 files changed, 68 insertions, 7 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml index 65d5633d5..8fb38998c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,16 @@ defaults: &defaults docker: - image: ubuntu:14.04 jobs: + sanity_check: + <<: *defaults + steps: + - checkout + - run: + name: Setup requirements + command: bash scripts/setup_common_requirements.sh + - run: + name: run sanity check script + command: bash scripts/ci_sanity_checks.sh build_linux: <<: *defaults steps: @@ -226,12 +236,25 @@ workflows: version: 2 build_all: jobs: - - build_linux - - build_android - - build_win32 - - build_wince - - build_tomtom_minimal - - build_tomtom_plugin + - sanity_check + - build_linux: + requires: + - sanity_check + - build_android: + requires: + - sanity_check + - build_win32: + requires: + - sanity_check + - build_wince: + requires: + - sanity_check + - build_tomtom_minimal: + requires: + - sanity_check + - build_tomtom_plugin: + requires: + - sanity_check - run_doxygen: requires: - build_linux diff --git a/scripts/ci_sanity_checks.sh b/scripts/ci_sanity_checks.sh new file mode 100755 index 000000000..acca359ec --- /dev/null +++ b/scripts/ci_sanity_checks.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -x +set -eu + +# ############################################################################# +# This script runs on circle CI to verify that the code of the PR has been +# sanitized before push. +# ############################################################################# + +# List the files that are different from the trunk +from=$(git rev-parse refs/remotes/origin/trunk) +to=$(git rev-parse HEAD) +interval=${from}..${to} +[[ "${from}" == "${to}" ]] && interval=${to} + +for f in $(git show -m --pretty="format:" --name-only ${interval}); do + if [[ -e "${f}" ]]; then + echo $f + if [[ "$f" != "*.bat" ]]; then + # Removes trailing spaces + [[ "$(file -bi """${f}""")" =~ ^text ]] && sed 's/\s*$//' -i "${f}" + fi + # Formats any *.c and *.cpp files + if [[ "$f" == "*.c" ]] || [[ "$f" == "*.cpp" ]]; then + astyle --indent=spaces=4 --style=attach -n --max-code-length=120 -xf -xh "${f}" + fi + fi +done + +# Check if any file has been modified. If yes, that means the best practices +# have not been followed, so we fail the job. +git diff --exit-code +code=$? +if [[ $code -ne 0 ]]; then + echo "You may need to do some cleanup in the files you commited, see the git diff output above." +fi +git checkout -- . +exit $code diff --git a/scripts/setup_common_requirements.sh b/scripts/setup_common_requirements.sh index 6343194bb..7156fbadc 100644 --- a/scripts/setup_common_requirements.sh +++ b/scripts/setup_common_requirements.sh @@ -1,4 +1,4 @@ #!/bin/sh set -e -apt-get update && apt-get install -y wget unzip cmake build-essential gettext librsvg2-bin util-linux git ssh +apt-get update && apt-get install -y wget unzip cmake build-essential gettext librsvg2-bin util-linux git ssh sed astyle |