-
Notifications
You must be signed in to change notification settings - Fork 71
/
action.yaml
225 lines (207 loc) · 7 KB
/
action.yaml
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: "ShellCheck"
author: "Ludeeus <hi@ludeeus.dev>"
description: "GitHub action for ShellCheck."
inputs:
additional_files:
description: "A space separated list of additional filename to check"
required: false
default: ""
ignore:
description: "Paths to ignore when running ShellCheck"
required: false
default: ""
deprecationMessage: "Use ignore_paths or ignore_names instead."
ignore_paths:
description: "Paths to ignore when running ShellCheck"
required: false
default: ""
ignore_names:
description: "Names to ignore when running ShellCheck"
required: false
default: ""
severity:
description: "Minimum severity of errors to consider. Options: [error, warning, info, style]"
required: false
default: ""
check_together:
description: "Run shellcheck on _all_ files at once, instead of one at a time"
required: false
default: ""
scandir:
description: "Directory to be searched for files. Defaults to ."
required: false
default: "."
disable_matcher:
description: "Set to true to skip using problem-matcher"
required: false
default: "false"
deprecationMessage: "There are no problem-matchers, this setting does not do anything."
format:
description: "Output format (checkstyle, diff, gcc, json, json1, quiet, tty)"
required: false
default: "gcc"
version:
description: "Specify a concrete version of ShellCheck to use"
required: false
default: "stable"
outputs:
files:
description: A list of files with issues
value: ${{ steps.check.outputs.filepaths }}
options:
description: The options used
value: ${{ steps.options.outputs.options }}
branding:
icon: "terminal"
color: "gray-dark"
runs:
using: "composite"
steps:
- name: Download shellcheck
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
if [[ "${{ runner.os }}" == "macOS" ]]; then
osvariant="darwin"
else
osvariant="linux"
fi
baseurl="https://github.com/koalaman/shellcheck/releases/download"
curl -Lso "${{ github.action_path }}/sc.tar.xz" \
"${baseurl}/${INPUT_VERSION}/shellcheck-${INPUT_VERSION}.${osvariant}.x86_64.tar.xz"
tar -xf "${{ github.action_path }}/sc.tar.xz" -C "${{ github.action_path }}"
mv "${{ github.action_path }}/shellcheck-${INPUT_VERSION}/shellcheck" \
"${{ github.action_path }}/shellcheck"
- name: Display shellcheck version
shell: bash
run: |
"${{ github.action_path }}/shellcheck" --version
- name: Set options
shell: bash
id: options
env:
INPUT_SEVERITY: ${{ inputs.severity }}
INPUT_FORMAT: ${{ inputs.format }}
run: |
declare -a options
if [[ -n "${INPUT_SEVERITY}" ]]; then
options+=("-S ${INPUT_SEVERITY}")
fi
options+=("--format=${INPUT_FORMAT}")
echo "options=${options[@]}" >> $GITHUB_OUTPUT
- name: Gather excluded paths
shell: bash
id: exclude
env:
INPUT_IGNORE: ${{ inputs.ignore }}
INPUT_IGNORE_PATHS: ${{ inputs.ignore_paths }}
INPUT_IGNORE_NAMES: ${{ inputs.ignore_names }}
run: |
declare -a excludes
set -f # temporarily disable globbing so that globs in input aren't expanded
excludes+=("! -path *./.git/*")
excludes+=("! -path *.go")
excludes+=("! -path */mvnw")
if [[ -n "${INPUT_IGNORE}" ]]; then
for path in ${INPUT_IGNORE}; do
excludes+=("! -path *./$path/*")
excludes+=("! -path */$path/*")
excludes+=("! -path $path")
done
else
for path in ${INPUT_IGNORE_PATHS}; do
excludes+=("! -path *./$path/*")
excludes+=("! -path */$path/*")
excludes+=("! -path $path")
done
fi
for name in ${INPUT_IGNORE_NAMES}; do
excludes+=("! -name $name")
done
echo "excludes=${excludes[@]}" >> $GITHUB_OUTPUT
set +f # re-enable globbing
- name: Gather additional files
shell: bash
id: additional
env:
INPUT_ADDITIONAL_FILES: ${{ inputs.additional_files }}
run: |
declare -a files
for file in ${INPUT_ADDITIONAL_FILES}; do
files+=("-o -name *$file")
done
echo "files=${files[@]}" >> $GITHUB_OUTPUT
- name: Run the check
shell: bash
id: check
env:
INPUT_SCANDIR: ${{ inputs.scandir }}
INPUT_CHECK_TOGETHER: ${{ inputs.check_together }}
INPUT_EXCLUDE_ARGS: ${{ steps.exclude.outputs.excludes }}
INPUT_ADDITIONAL_FILE_ARGS: ${{ steps.additional.outputs.files }}
INPUT_SHELLCHECK_OPTIONS: ${{ steps.options.outputs.options }}
run: |
statuscode=0
declare -a filepaths
shebangregex="^#! */[^ ]*/(env *)?[abk]*sh"
set -f # temporarily disable globbing so that globs in inputs aren't expanded
while IFS= read -r -d '' file; do
filepaths+=("$file")
done < <(find "${INPUT_SCANDIR}" \
${INPUT_EXCLUDE_ARGS} \
-type f \
'(' \
-name '*.bash' \
-o -name '.bashrc' \
-o -name 'bashrc' \
-o -name '.bash_aliases' \
-o -name '.bash_completion' \
-o -name '.bash_login' \
-o -name '.bash_logout' \
-o -name '.bash_profile' \
-o -name 'bash_profile' \
-o -name '*.ksh' \
-o -name 'suid_profile' \
-o -name '*.zsh' \
-o -name '.zlogin' \
-o -name 'zlogin' \
-o -name '.zlogout' \
-o -name 'zlogout' \
-o -name '.zprofile' \
-o -name 'zprofile' \
-o -name '.zsenv' \
-o -name 'zsenv' \
-o -name '.zshrc' \
-o -name 'zshrc' \
-o -name '*.sh' \
-o -path '*/.profile' \
-o -path '*/profile' \
-o -name '*.shlib' \
${INPUT_ADDITIONAL_FILE_ARGS} \
')' \
-print0)
while IFS= read -r -d '' file; do
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
filepaths+=("$file")
done < <(find "${INPUT_SCANDIR}" \
${INPUT_EXCLUDE_ARGS} \
-type f ! -name '*.*' -perm /111 \
-print0)
if [[ -n "${INPUT_CHECK_TOGETHER}" ]]; then
"${{ github.action_path }}/shellcheck" \
${INPUT_SHELLCHECK_OPTIONS} \
"${filepaths[@]}" || statuscode=$?
else
for file in "${filepaths[@]}"; do
"${{ github.action_path }}/shellcheck" \
${INPUT_SHELLCHECK_OPTIONS} \
"$file" || statuscode=$?
done
fi
echo "filepaths=${filepaths[@]}" >> $GITHUB_OUTPUT
echo "statuscode=$statuscode" >> $GITHUB_OUTPUT
set +f # re-enable globbing
- name: Exit action
shell: bash
run: exit ${{steps.check.outputs.statuscode}}