-
Notifications
You must be signed in to change notification settings - Fork 67
/
action.yaml
199 lines (182 loc) · 6.33 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
name: "ShellCheck"
author: "Ludeeus <hi@ludeeus.dev>"
description: "GitHub action for ShellCheck."
inputs:
additional_files:
description: "A space seperated list of additional filename to check"
required: false
default: ""
ignore:
description: "Paths 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"
outputs:
files:
description: A list of files with issues
value: ${{ steps.filepaths.outputs.filepaths }}
options:
description: The options used
value: ${{ steps.options.outputs.options }}
branding:
icon: "terminal"
color: "gray-dark"
runs:
using: "composite"
steps:
- name: Enable problem-matcher
shell: bash
run: |
if [[ ${{ inputs.disable_matcher }} != "true" ]]; then
echo "::add-matcher::${{ github.action_path }}/.github/problem-matcher.json"
fi
- name: Download shellcheck
shell: bash
run: |
if [[ "${{ runner.os }}" == "macOS" ]]; then
osvariant="darwin"
else
osvariant="linux"
fi
scversion="stable"
baseurl="https://github.com/koalaman/shellcheck/releases/download"
curl -Lso "${{ github.action_path }}/sc.tar.xz" \
"${baseurl}/${scversion}/shellcheck-${scversion}.${osvariant}.x86_64.tar.xz"
tar -xf "${{ github.action_path }}/sc.tar.xz" -C "${{ github.action_path }}"
mv "${{ github.action_path }}/shellcheck-${scversion}/shellcheck" \
"${{ github.action_path }}/shellcheck"
- name: Set options
shell: bash
id: options
run: |
declare -a options
if [[ -n "${{ inputs.severity }}" ]]; then
options+=("-S ${{ inputs.severity }}")
fi
echo "::set-output name=options::${options[@]}"
- name: Gather excluded paths
shell: bash
id: exclude
run: |
declare -a excludes
excludes+=("! -path \"*./.git/*\"")
excludes+=("! -path \"*.go\"")
excludes+=("! -path \"*/mvnw\"")
for path in ${{ inputs.ignore }}; do
echo "::debug:: Adding "$path" to excludes"
excludes+=("! -path \"*./$path/*\"")
excludes+=("! -path \"*/$path/*\"")
done
echo "::set-output name=excludes::${excludes[@]}"
- name: Gather additional files
shell: bash
id: additional
run: |
declare -a files
for file in ${{ inputs.additional_files }}; do
echo "::debug:: Adding "$file" to excludes"
files+=("-o -name \"*$file\"")
done
echo "::set-output name=files::${files[@]}"
- name: Gather base file paths
shell: bash
id: filepaths
run: |
declare -a filepaths
shebangregex="^#! */[^ ]*/(env *)?[abkz]*sh"
for path in $(find "${{ inputs.scandir }}" \
-type f -type f ${{ steps.exclude.outputs.excludes }} \
'(' \
-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' \
${{ steps.additional.outputs.files }} \
')'\
-print); do
filepaths+=("$path");
done
for file in $(find "${{ inputs.scandir }}" ${{ steps.exclude.outputs.excludes }} -type f ! -name '*.*' -perm /111 -print); do
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
filepaths+=("$file");
done
echo "::set-output name=filepaths::${filepaths[@]}"
- name: Check bin subdirs
shell: bash
run: |
if find "${{ inputs.scandir }}" ${{ steps.exclude.outputs.excludes }} -path '*bin/*/*' -type f -perm /111 -print |
grep .
then
echo "::warning:: subdirectories of bin directories are not usable via PATH"
fi
- name: Check no suffix in PATH
shell: bash
run: |
if find "${{ inputs.scandir }}" ${{ steps.exclude.outputs.excludes }} -path '*bin/*' -name '*.*' -type f -perm /111 -perm /444 -print |
grep .
then
echo "::warning:: programs in PATH should not have a filename suffix"
fi
- name: Run the file check
id: check
shell: bash
run: |
statuscode=0
if [[ -n "${{ inputs.check_together }}" ]]; then
"${{ github.action_path }}/shellcheck" \
${{ steps.options.outputs.options }} \
${{ steps.filepaths.outputs.filepaths }} || statuscode=$?
else
for file in ${{ steps.filepaths.outputs.filepaths }}; do
echo "::debug::Checking $file"
"${{ github.action_path }}/shellcheck" \
${{ steps.options.outputs.options }} \
"$file" || statuscode=$?;
done
fi
echo "::set-output name=statuscode::$statuscode"
- name: Print information
shell: bash
run: |
echo "Files: ${{steps.filepaths.outputs.filepaths}}"
echo "Excluded: ${{ steps.exclude.outputs.excludes }}"
echo "Options: ${{ steps.options.outputs.options }}"
echo "Status code: ${{steps.check.outputs.statuscode}}"
exit ${{steps.check.outputs.statuscode}}