forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shellCheck.sh
executable file
·48 lines (38 loc) · 1.15 KB
/
shellCheck.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
CURRENT_DIR=$(pwd)
ROOT_DIR=$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")
cd "$ROOT_DIR" || exit 1
source scripts/shellUtils.sh
declare -r DIRECTORIES_TO_IGNORE=(
'./node_modules'
'./vendor'
'./ios/Pods'
'./.husky'
)
# This lists all shell scripts in this repo except those in directories we want to ignore
read -ra IGNORE_DIRS < <(join_by_string ' -o -path ' "${DIRECTORIES_TO_IGNORE[@]}")
SHELL_SCRIPTS=$(find . -type d \( -path "${IGNORE_DIRS[@]}" \) -prune -o -name '*.sh' -print)
info "👀 Linting the following shell scripts using ShellCheck: $SHELL_SCRIPTS"
info
ASYNC_PROCESSES=()
for SHELL_SCRIPT in $SHELL_SCRIPTS; do
if [[ "$CI" == 'true' ]]; then
# ShellCheck is installed by default on GitHub Actions ubuntu runners
shellcheck -e SC1091 "$SHELL_SCRIPT" &
else
# Otherwise shellcheck is used via npx
npx shellcheck -e SC1091 "$SHELL_SCRIPT" &
fi
ASYNC_PROCESSES+=($!)
done
EXIT_CODE=0
for PID in "${ASYNC_PROCESSES[@]}"; do
if ! wait "$PID"; then
EXIT_CODE=1
fi
done
cd "$CURRENT_DIR" || exit 1
if [ $EXIT_CODE == 0 ]; then
success "ShellCheck passed for all files!"
fi
exit $EXIT_CODE