From c5c39036174c845588b3cb967d6eb7cb90523829 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Thu, 3 May 2018 11:35:09 +0200 Subject: [PATCH] shellcheck: Add CI check script --- dist/tools/shellcheck/check.sh | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 dist/tools/shellcheck/check.sh diff --git a/dist/tools/shellcheck/check.sh b/dist/tools/shellcheck/check.sh new file mode 100755 index 0000000000..d372d1a63e --- /dev/null +++ b/dist/tools/shellcheck/check.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2018 Freie Universität Berlin +# Inria +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +SHELLCHECK_CMD="$(command -v shellcheck)" +export SHELLCHECK_OPTS="-e SC1090" + +if tput colors &> /dev/null && [ "$(tput colors)" -ge 8 ]; then + CERROR=$'\e[1;31m' + CRESET=$'\e[0m' +else + CERROR= + CRESET= +fi + +: "${RIOTTOOLS:=${PWD}/dist/tools}" +. "${RIOTTOOLS}"/ci/changed_files.sh + +FILES=$(FILEREGEX='(.*\.sh$)' changed_files) + +if [ -z "${FILES}" ] +then + exit 0 +fi + +${SHELLCHECK_CMD} --version &> /dev/null || { + printf "%sError: Shellcheck command is missing%s\n" "${CERROR}" "${CRESET}" + exit 1 +} + +ERRORS=$("${SHELLCHECK_CMD}" --format=gcc ${FILES}) + +if [ -n "${ERRORS}" ] +then + printf "%s There are issues in the following shell scripts %s\n" "${CERROR}" "${CRESET}" + printf "%s\n" "${ERRORS}" + exit 1 +else + exit 0 +fi