Merge pull request #15756 from miri64/dist/enh/shellcheck-enabled
static_tests: enable shellcheck and annote its output
This commit is contained in:
commit
09463b73cb
8
dist/tools/ci/static_tests.sh
vendored
8
dist/tools/ci/static_tests.sh
vendored
@ -10,7 +10,7 @@
|
|||||||
# directory for more details.
|
# directory for more details.
|
||||||
#
|
#
|
||||||
|
|
||||||
. $(dirname "$0")/github_annotate.sh
|
. "$(dirname "${0}")"/github_annotate.sh
|
||||||
|
|
||||||
declare -A DEPS
|
declare -A DEPS
|
||||||
|
|
||||||
@ -22,8 +22,9 @@ DEPS["./dist/tools/coccinelle/check.sh"]="spatch"
|
|||||||
DEPS["./dist/tools/flake8/check.sh"]="python3 flake8"
|
DEPS["./dist/tools/flake8/check.sh"]="python3 flake8"
|
||||||
DEPS["./dist/tools/codespell/check.sh"]="codespell"
|
DEPS["./dist/tools/codespell/check.sh"]="codespell"
|
||||||
DEPS["./dist/tools/uncrustify/uncrustify.sh"]="uncrustify"
|
DEPS["./dist/tools/uncrustify/uncrustify.sh"]="uncrustify"
|
||||||
|
DEPS["./dist/tools/shellcheck/shellcheck.sh"]="shellcheck"
|
||||||
|
|
||||||
if ! command -v git 2>&1 1>/dev/null; then
|
if ! command -v git &>/dev/null; then
|
||||||
echo -n "Required command 'git' for all static tests not found in PATH "
|
echo -n "Required command 'git' for all static tests not found in PATH "
|
||||||
print_warning
|
print_warning
|
||||||
set_result 1
|
set_result 1
|
||||||
@ -60,7 +61,7 @@ set_result() {
|
|||||||
|
|
||||||
function run {
|
function run {
|
||||||
for dep in ${DEPS["$1"]}; do
|
for dep in ${DEPS["$1"]}; do
|
||||||
if ! command -v ${dep} 2>&1 1>/dev/null; then
|
if ! command -v ${dep} &>/dev/null; then
|
||||||
echo -n "Required command '${dep}' for '$*' not found in PATH "
|
echo -n "Required command '${dep}' for '$*' not found in PATH "
|
||||||
print_warning
|
print_warning
|
||||||
set_result 1
|
set_result 1
|
||||||
@ -120,5 +121,6 @@ if [ -z "${GITHUB_RUN_ID}" ]; then
|
|||||||
else
|
else
|
||||||
run ./dist/tools/uncrustify/uncrustify.sh
|
run ./dist/tools/uncrustify/uncrustify.sh
|
||||||
fi
|
fi
|
||||||
|
ERROR_EXIT_CODE=0 run ./dist/tools/shellcheck/check.sh
|
||||||
|
|
||||||
exit $RESULT
|
exit $RESULT
|
||||||
|
|||||||
39
dist/tools/shellcheck/check.sh
vendored
39
dist/tools/shellcheck/check.sh
vendored
@ -21,6 +21,7 @@ fi
|
|||||||
|
|
||||||
: "${RIOTTOOLS:=${PWD}/dist/tools}"
|
: "${RIOTTOOLS:=${PWD}/dist/tools}"
|
||||||
. "${RIOTTOOLS}"/ci/changed_files.sh
|
. "${RIOTTOOLS}"/ci/changed_files.sh
|
||||||
|
. "${RIOTTOOLS}"/ci/github_annotate.sh
|
||||||
|
|
||||||
FILES=$(FILEREGEX='(.*\.sh$)' changed_files)
|
FILES=$(FILEREGEX='(.*\.sh$)' changed_files)
|
||||||
|
|
||||||
@ -34,13 +35,41 @@ ${SHELLCHECK_CMD} --version &> /dev/null || {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
ERRORS=$("${SHELLCHECK_CMD}" --format=gcc ${FILES})
|
github_annotate_setup
|
||||||
|
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
# FILES is supposed to be split, so don't quote it
|
||||||
|
ERRORS="$("${SHELLCHECK_CMD}" --format=gcc ${FILES})"
|
||||||
|
|
||||||
|
EXIT_CODE=0
|
||||||
|
|
||||||
if [ -n "${ERRORS}" ]
|
if [ -n "${ERRORS}" ]
|
||||||
then
|
then
|
||||||
printf "%s There are issues in the following shell scripts %s\n" "${CERROR}" "${CRESET}"
|
if github_annotate_is_on; then
|
||||||
printf "%s\n" "${ERRORS}"
|
echo "${ERRORS}" | while read -r error; do
|
||||||
exit 1
|
FILENAME=$(echo "${error}" | cut -d: -f1)
|
||||||
|
LINENUM=$(echo "${error}" | cut -d: -f2)
|
||||||
|
SEVERITY=$(echo "${error}" | cut -d: -f4)
|
||||||
|
DETAILS=$(echo "${error}" | cut -d: -f5- |
|
||||||
|
sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
|
||||||
|
if echo "${SEVERITY}" | grep -q 'error'; then
|
||||||
|
github_annotate_error "${FILENAME}" "${LINENUM}" "${DETAILS}"
|
||||||
else
|
else
|
||||||
exit 0
|
github_annotate_warning "${FILENAME}" "${LINENUM}" "${DETAILS}"
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
printf "%s There are issues in the following shell scripts %s\n" \
|
||||||
|
"${CERROR}" "${CRESET}"
|
||||||
|
printf "%s\n" "${ERRORS}"
|
||||||
|
fi
|
||||||
|
if [ -z "${ERROR_EXIT_CODE}" ]; then
|
||||||
|
EXIT_CODE=1
|
||||||
|
else
|
||||||
|
EXIT_CODE="${ERROR_EXIT_CODE}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
github_annotate_teardown
|
||||||
|
|
||||||
|
exit "${EXIT_CODE}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user