-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
77 lines (54 loc) · 2.04 KB
/
entrypoint.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
# Set variables
ACTIONSTATUS=0
EXITSTATUS=0
FILECOUNT=0
LOOPCOUNT=0
INPUT_EXTRA_PARAMS="${INPUT_EXTRA_PARAMS:-}"
INPUT_FIND_PATH="${INPUT_FIND_PATH:-.}"
INPUT_FAIL_ON_ERROR="${INPUT_FAIL_ON_ERROR:-true}"
cd "${GITHUB_WORKSPACE}"
if [ -n "${INPUT_FILE_LIST}" ]; then
2>&1 echo "==> File List ${INPUT_FILE_LIST} specified. Linting files matching this pattern."
IFS=', ' read -r -a FILELIST <<< "${INPUT_FILE_LIST}"
else
if [ ! -d "${INPUT_FIND_PATH}" ]; then
2>&1 echo "==> Can't find ${INPUT_FIND_PATH}. Please ensure INPUT_FIND_PATH is a directory relative to the root of your project."
exit 1
fi
if [[ -n "${INPUT_FIND_PATTERN}" ]]; then
2>&1 echo "==> Pattern ${INPUT_FIND_PATTERN} specified. Finding files matching this pattern."
readarray -d '' FILELIST < <(find "${INPUT_FIND_PATH}" -name "${INPUT_FIND_PATTERN}" -print0)
else
2>&1 echo "INPUT_FIND_PATTERN is not set. Using '*.csv'"
readarray -d '' FILELIST < <(find "${INPUT_FIND_PATH}" -name "*.csv" -print0)
fi
fi
FILECOUNT=${#FILELIST[@]}
2>&1 echo "==> Found ${FILECOUNT} files to Lint."
if [ "${FILECOUNT}" -eq 0 ]; then
2>&1 echo "==> Nothing to do. Exiting."
exit 0
fi
trap '' ERR
for FILE in "${FILELIST[@]}"; do
LOOPCOUNT=$((LOOPCOUNT+1))
2>&1 echo "==> Linting ${LOOPCOUNT} of ${FILECOUNT}. FILE: ${FILE}"
/usr/local/sbin/csvlint ${INPUT_EXTRA_PARAMS} "${FILE}"
EXITSTATUS=$?
if [ ${EXITSTATUS} -ne 0 ]; then
2>&1 echo "==> Linting errors found for ${FILE}."
ACTIONSTATUS=${EXITSTATUS}
fi
done
# Exit with the status of the last command and user input
if [ ${INPUT_FAIL_ON_ERROR} = "true" ] && [ ${ACTIONSTATUS} -ne 0 ]; then
2>&1 echo "==> Linting errors found and fail_on_error is true. Exiting with error."
exit ${ACTIONSTATUS}
elif [ ${INPUT_FAIL_ON_ERROR} = "false" ] && [ ${ACTIONSTATUS} -ne 0 ]; then
2>&1 echo "==> Linting errors found and fail_on_error is false. Check logs for errors."
exit 0
else
2>&1 echo "==> No linting errors found. Exiting with success."
exit 0
fi