summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJoseph Herlant <aerostitch@users.noreply.github.com>2018-06-02 23:12:52 -0700
committerjkoan <jkoan@users.noreply.github.com>2018-06-03 08:12:52 +0200
commit34ce7f49f55d58daabf5121f0d906c55ef695579 (patch)
treea048b89b8394ae9cffb1e22a043b4b01ce1a1d3c /scripts
parentb57107832fe5c904b804e7946ca03d550523c540 (diff)
downloadnavit-34ce7f49f55d58daabf5121f0d906c55ef695579.tar.gz
update:ci:Refactor the sanity check for better output and add xmllint check (#609)
* update:ci:Refactor the sanity check for better output and add xmllint check * Use sort -u * Switch to git diff with trunk so that we avoid re-checking files coming from merge commits * Make sure to really take the extension properly in the comparison
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/ci_sanity_checks.sh62
1 files changed, 43 insertions, 19 deletions
diff --git a/scripts/ci_sanity_checks.sh b/scripts/ci_sanity_checks.sh
index acca359ec..7adf185f6 100755
--- a/scripts/ci_sanity_checks.sh
+++ b/scripts/ci_sanity_checks.sh
@@ -1,11 +1,27 @@
#!/usr/bin/env bash
-set -x
-set -eu
+set -u
-# #############################################################################
+# #####################################################################################################################
# This script runs on circle CI to verify that the code of the PR has been
# sanitized before push.
-# #############################################################################
+#
+# WARNING: make sure you commit ALL your changes before running it locally if you ever do it because it will run a git
+# checkout -- which will reset your changes on all files...
+# #####################################################################################################################
+
+return_code=0
+
+# Check if any file has been modified. If yes, that means the best practices
+# have not been followed, so we will fail the job later but print a message here.
+check_diff(){
+ git diff --exit-code
+ code=$?
+ if [[ $code -ne 0 ]]; then
+ echo "[ERROR] You may need to do some cleanup in the files you commited, see the git diff output above."
+ fi
+ git checkout -- .
+ return_code=$(($return_code + $code))
+}
# List the files that are different from the trunk
from=$(git rev-parse refs/remotes/origin/trunk)
@@ -13,26 +29,34 @@ to=$(git rev-parse HEAD)
interval=${from}..${to}
[[ "${from}" == "${to}" ]] && interval=${to}
-for f in $(git show -m --pretty="format:" --name-only ${interval}); do
+for f in $(git diff --name-only ${interval} | sort -u); do
if [[ -e "${f}" ]]; then
- echo $f
- if [[ "$f" != "*.bat" ]]; then
- # Removes trailing spaces
- [[ "$(file -bi """${f}""")" =~ ^text ]] && sed 's/\s*$//' -i "${f}"
+
+ # Checks for trailing spaces
+ if [[ "${f: -4}" != ".bat" ]]; then
+ echo "[INFO] Checking for trailing spaces on ${f}..."
+ if [[ "$(file -bi """${f}""")" =~ ^text ]]; then
+ sed 's/\s*$//' -i "${f}"
+ check_diff
+ fi
fi
+
# Formats any *.c and *.cpp files
- if [[ "$f" == "*.c" ]] || [[ "$f" == "*.cpp" ]]; then
+ if [[ "${f: -2}" == ".c" ]] || [[ "${f: -4}" == ".cpp" ]]; then
+ echo "[INFO] Checking for indentation and style compliance on ${f}..."
astyle --indent=spaces=4 --style=attach -n --max-code-length=120 -xf -xh "${f}"
+ check_diff
+ fi
+
+ if [[ "${f}" == "navit/navit_shipped.xml" ]]; then
+ echo "[INFO] Checking for compliance with the DTD using xmllint on ${f}..."
+ xmllint --noout --dtdvalid navit/navit.dtd "$f"
+ rc=$?
+ if [[ $rc -ne 0 ]]; then
+ echo "[ERROR] Your ${f} file doesn't validate against the navit/navit.dtd using xmllint"
+ fi
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
+exit $return_code