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 /scripts/ci_sanity_checks.sh | |
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
Diffstat (limited to 'scripts/ci_sanity_checks.sh')
-rwxr-xr-x | scripts/ci_sanity_checks.sh | 38 |
1 files changed, 38 insertions, 0 deletions
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 |