aboutsummaryrefslogtreecommitdiff
path: root/tests/shellchecks.sh
diff options
context:
space:
mode:
authorGravatar Frans de Jonge <fransdejonge@gmail.com> 2019-07-22 16:07:40 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2019-07-22 16:07:40 +0200
commitad92518fe44279b69308aaf0a757469f5bf42910 (patch)
tree4d85581537d53095346e5d443c156e49b41b6053 /tests/shellchecks.sh
parent71270e4d5c7f0645a31a8dc7ccc56cea6a9711b0 (diff)
[CI] Run shellcheck and shfmt (#2454)
* [CI] Run shellcheck and shfmt Cf. https://github.com/FreshRSS/FreshRSS/pull/2436#discussion_r305640019 * rename * no need for disable anymore * also remove leftover indentation flags even if it makes no difference to syntax checking * define colors and reset before exit for local use
Diffstat (limited to 'tests/shellchecks.sh')
-rwxr-xr-xtests/shellchecks.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/shellchecks.sh b/tests/shellchecks.sh
new file mode 100755
index 000000000..648f2766e
--- /dev/null
+++ b/tests/shellchecks.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+# Based on https://github.com/koreader/koreader/blob/master/.ci/helper_shellchecks.sh
+
+ANSI_RED="\\033[31;1m"
+ANSI_GREEN="\\033[32;1m"
+ANSI_RESET="\\033[0m"
+
+mapfile -t shellscript_locations < <({ git grep -lE '^#!(/usr)?/bin/(env )?(bash|sh)' && git ls-files ./*.sh; } | sort | uniq)
+
+SHELLSCRIPT_ERROR=0
+
+for shellscript in "${shellscript_locations[@]}"; do
+ echo -e "${ANSI_GREEN}Running shellcheck on ${shellscript}"
+ shellcheck "${shellscript}" || SHELLSCRIPT_ERROR=1
+ echo -e "${ANSI_GREEN}Running shfmt on ${shellscript}"
+ if ! shfmt "${shellscript}" >/dev/null 2>&1; then
+ echo -e "${ANSI_RED}Warning: ${shellscript} contains the following problem:"
+ shfmt "${shellscript}" || SHELLSCRIPT_ERROR=1
+ continue
+ fi
+ if [ "$(cat "${shellscript}")" != "$(shfmt "${shellscript}")" ]; then
+ echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style, diff for expected style:"
+ shfmt "${shellscript}" | diff "${shellscript}" - || SHELLSCRIPT_ERROR=1
+ fi
+done
+
+echo -ne "${ANSI_RESET}"
+
+exit "${SHELLSCRIPT_ERROR}"