-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·134 lines (116 loc) · 4.69 KB
/
Copy pathscript.sh
File metadata and controls
executable file
·134 lines (116 loc) · 4.69 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
set -u
echo '::group:: Installing shellcheck ... https://github.com/koalaman/shellcheck'
TEMP_PATH="$(mktemp -d)"
cd "${TEMP_PATH}" || exit
mkdir bin
WINDOWS_TARGET=zip
# Get system architecture
ARCH=$(uname -m)
if [[ "${ARCH}" == "arm64" || "${ARCH}" == "aarch64" ]]; then
CPU_ARCH="aarch64"
else
CPU_ARCH="x86_64"
fi
# Set targets based on OS and architecture
if [[ $(uname -s) == "Linux" ]]; then
LINUX_TARGET="linux.${CPU_ARCH}.tar.xz"
curl -sL "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${LINUX_TARGET}" | tar -xJf -
cp "shellcheck-v$SHELLCHECK_VERSION/shellcheck" ./bin
elif [[ $(uname -s) == "Darwin" ]]; then
MACOS_TARGET="darwin.${CPU_ARCH}.tar.xz"
curl -sL "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${MACOS_TARGET}" | tar -xJf -
cp "shellcheck-v$SHELLCHECK_VERSION/shellcheck" ./bin
else
curl -sL "https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.${WINDOWS_TARGET}" -o "shellcheck-v${SHELLCHECK_VERSION}.${WINDOWS_TARGET}" && unzip "shellcheck-v${SHELLCHECK_VERSION}.${WINDOWS_TARGET}" && rm "shellcheck-v${SHELLCHECK_VERSION}.${WINDOWS_TARGET}"
cp "shellcheck.exe" ./bin
fi
PATH="${TEMP_PATH}/bin:$PATH"
shellcheck --version
echo '::endgroup::'
cd "${GITHUB_WORKSPACE}" || exit
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
paths=()
while read -r pattern; do
[[ -n ${pattern} ]] && paths+=("${pattern}")
done <<< "${INPUT_PATH:-.}"
names=()
if [[ "${INPUT_PATTERN:-*}" != '*' ]]; then
while read -r pattern; do
[[ -n ${pattern} ]] && names+=(-o -name "${pattern}")
done <<< "${INPUT_PATTERN}"
(( ${#names[@]} )) && { names[0]='('; names+=(')'); }
fi
excludes=()
while read -r pattern; do
[[ -n ${pattern} ]] && excludes+=(-not -path "${pattern}")
done <<< "${INPUT_EXCLUDE:-}"
# Collect matches NUL-separated so that paths containing whitespace survive
files=()
# Match all files matching the pattern
while IFS= read -r -d '' file; do
files+=("${file}")
done < <(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}" -print0)
# Match all files with a shebang (e.g. "#!/usr/bin/env zsh" or even "#!bash") in the first line of a file
# Ignore files which match "$pattern" in order to avoid duplicates
if [ "${INPUT_CHECK_ALL_FILES_WITH_SHEBANGS}" = "true" ]; then
while IFS= read -r -d '' file; do
files+=("${file}")
done < <(find "${paths[@]}" "${excludes[@]}" -not "${names[@]}" -type f -print0 \
| xargs -0 awk 'FNR==1 && /^#!.*sh/ { printf "%s%c", FILENAME, 0 }')
fi
# Exit early if no files have been found
if [ ${#files[@]} -eq 0 ]; then
echo "No matching files found to check."
exit 0
fi
echo '::group:: Running shellcheck ...'
if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then
# erroformat: https://git.io/JeGMU
# shellcheck disable=SC2086
shellcheck -f json ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} "${files[@]}" \
| jq -r '.[] | "\(.file):\(.line):\(.column):\(.level):\(.message) [SC\(.code)](https://github.com/koalaman/shellcheck/wiki/SC\(.code))"' \
| reviewdog \
-efm="%f:%l:%c:%t%*[^:]:%m" \
-name="shellcheck" \
-reporter=github-pr-review \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-level="${INPUT_FAIL_LEVEL}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
${INPUT_REVIEWDOG_FLAGS}
EXIT_CODE=$?
else
# github-pr-check,github-check (GitHub Check API) doesn't support markdown annotation.
# shellcheck disable=SC2086
shellcheck -f checkstyle ${INPUT_SHELLCHECK_FLAGS:-'--external-sources'} "${files[@]}" \
| reviewdog \
-f="checkstyle" \
-name="shellcheck" \
-reporter="${INPUT_REPORTER:-github-pr-check}" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-level="${INPUT_FAIL_LEVEL}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
${INPUT_REVIEWDOG_FLAGS}
EXIT_CODE=$?
fi
echo '::endgroup::'
echo '::group:: Running shellcheck (suggestion) ...'
# -reporter must be github-pr-review for the suggestion feature.
# shellcheck disable=SC2086
shellcheck -f diff "${files[@]}" \
| reviewdog \
-name="shellcheck (suggestion)" \
-f=diff \
-f.diff.strip=1 \
-reporter="github-pr-review" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-level="${INPUT_FAIL_LEVEL}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
${INPUT_REVIEWDOG_FLAGS}
EXIT_CODE_SUGGESTION=$?
echo '::endgroup::'
if [ "${EXIT_CODE}" -ne 0 ] || [ "${EXIT_CODE_SUGGESTION}" -ne 0 ]; then
exit $((EXIT_CODE + EXIT_CODE_SUGGESTION))
fi