2017-04-11 09:23:42 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
source "${CI_DIR}/common.sh"
|
|
|
|
|
|
|
|
# shellcheck disable=2016
|
2019-06-29 17:56:14 +00:00
|
|
|
mapfile -t shellscript_locations < <({ git grep -lE '^#!(/usr)?/bin/(env )?(bash|sh)' && git submodule --quiet foreach '[ "$path" = "base" -o "$path" = "platform/android/luajit-launcher" ] || git grep -lE "^#!(/usr)?/bin/(env )?(bash|sh)" | sed "s|^|$path/|"' && git ls-files ./*.sh; } | sort | uniq)
|
2017-04-11 09:23:42 +00:00
|
|
|
|
|
|
|
SHELLSCRIPT_ERROR=0
|
2020-11-25 14:50:47 +00:00
|
|
|
SHFMT_OPTIONS="-i 4 -ci"
|
2017-04-11 09:23:42 +00:00
|
|
|
|
|
|
|
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}"
|
2020-11-25 14:50:47 +00:00
|
|
|
# shellcheck disable=2086
|
|
|
|
if ! shfmt ${SHFMT_OPTIONS} -kp "${shellscript}" >/dev/null 2>&1; then
|
2017-04-27 08:25:17 +00:00
|
|
|
echo -e "${ANSI_RED}Warning: ${shellscript} contains the following problem:"
|
2020-11-25 14:50:47 +00:00
|
|
|
# shellcheck disable=2086
|
|
|
|
shfmt ${SHFMT_OPTIONS} -kp "${shellscript}" || SHELLSCRIPT_ERROR=1
|
2017-04-27 08:25:17 +00:00
|
|
|
continue
|
|
|
|
fi
|
2020-11-25 14:50:47 +00:00
|
|
|
# shellcheck disable=2086
|
|
|
|
if [ "$(cat "${shellscript}")" != "$(shfmt ${SHFMT_OPTIONS} "${shellscript}")" ]; then
|
2017-04-24 06:27:29 +00:00
|
|
|
echo -e "${ANSI_RED}Warning: ${shellscript} does not abide by coding style, diff for expected style:"
|
2020-11-25 14:50:47 +00:00
|
|
|
# shellcheck disable=2086
|
|
|
|
shfmt ${SHFMT_OPTIONS} -d "${shellscript}" || SHELLSCRIPT_ERROR=1
|
2017-04-11 09:28:01 +00:00
|
|
|
fi
|
2017-04-11 09:23:42 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
exit "${SHELLSCRIPT_ERROR}"
|