From b64d59d4574ff5ec16d5429d1b3e4f761f58b0f5 Mon Sep 17 00:00:00 2001 From: Joseph Herlant Date: Wed, 30 May 2018 11:21:59 -0700 Subject: 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 --- scripts/ci_sanity_checks.sh | 38 ++++++++++++++++++++++++++++++++++++ scripts/setup_common_requirements.sh | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 scripts/ci_sanity_checks.sh (limited to 'scripts') 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 -- cgit v1.2.1