-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpacefile.sh
More file actions
304 lines (278 loc) · 7.41 KB
/
Spacefile.sh
File metadata and controls
304 lines (278 loc) · 7.41 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#
# Copyright 2016-2017 Blockie AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# spacechecker - Space module analyzer
#
# Disable warning about indirectly checking status code
# shellcheck disable=SC2181
#=====================
# SPACECHECKER_DEP_INSTALL
#
# Check dependencies for this module.
#
#=====================
SPACECHECKER_DEP_INSTALL()
{
SPACE_DEP="PRINT" # shellcheck disable=SC2034
PRINT "Checking for dependencies." "info"
if [ "$?" -eq 0 ]; then
PRINT "Dependencies found." "ok"
else
PRINT "Failed finding dependencies." "error"
return 1
fi
}
# Disable warning about indirectly checking status code
# shellcheck disable=SC2181
#=====================
# _CHECK_DEP_INSTALL_NODE
#
# Check if module has dep_install node implemented.
#
#=====================
_CHECK_DEP_INSTALL_NODE()
{
space -f "$_dir_name/Spacefile.yaml" /_dep_install/ -h > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
PRINT "expected _dep_install node in Spacefile.yaml" "warning"
else
PRINT "OK" "ok"
fi
}
#=====================
# _CHECK_LICENSE_FILE_EXISTS
#
# Check if module has LICENSE file present.
#
#=====================
_CHECK_LICENSE_FILE_EXISTS()
{
if [ -f "$_dir_name/LICENSE" ] || [ -f "$_dir_name"/COPYING ]; then
PRINT "OK" "ok"
else
PRINT "expected LICENSE file" "warning"
fi
}
#=====================
# _CHECK_CHANGELOG_FILE_EXISTS
#
# Check if module has CHANGELOG file present.
#
#=====================
_CHECK_CHANGELOG_FILE_EXISTS()
{
if [ -f "$_dir_name/CHANGELOG.md" ]; then
PRINT "OK" "ok"
else
PRINT "expected CHANGELOG.md file" "warning"
fi
}
#=====================
# _CHECK_README_FILE_EXISTS
#
# Check if module has README file present.
#
#=====================
_CHECK_README_FILE_EXISTS()
{
if [ -f "$_dir_name/README.md" ]; then
PRINT "OK" "ok"
else
PRINT "expected README.md file" "warning"
fi
}
#=====================
# _CHECK_UPDATE_README_FILE_EXISTS
#
# Check if module has update_readme script present.
#
#=====================
_CHECK_UPDATE_README_FILE_EXISTS()
{
if [ -f "$_dir_name/update_readme.sh" ]; then
PRINT "OK" "ok"
else
PRINT "expected update_readme.sh file" "warning"
fi
}
#=====================
# _CHECK_STABLE_FILE_EXISTS
#
# Check if module has stable file present.
#
#=====================
_CHECK_STABLE_FILE_EXISTS()
{
if [ -f "$_dir_name/space-module.txt" ]; then
PRINT "OK" "ok"
else
PRINT "expected space-module.txt file" "warning"
fi
}
#=====================
# _CHECK_REQUIREMENT_FILE_EXISTS
#
# Check if module has requirement file present.
#
#=====================
_CHECK_REQUIREMENT_FILE_EXISTS()
{
if [ -f "$_dir_name/space-requirement.txt" ]; then
PRINT "OK" "ok"
else
PRINT "expected space-requirement.txt file" "warning"
fi
}
#=====================
# _CHECK_TESTS_EXIST
#
# Check if module has tests structure in place.
#
#=====================
_CHECK_TESTS_EXIST()
{
if [ -d "$_dir_name/test" ]; then
if [ -f "$_dir_name/test/test.yaml" ] \
&& [ -f "$_dir_name/test/test.sh" ]; then
PRINT "OK" "ok"
else
PRINT "expected test.yaml,sh in the test directory " "warning"
fi
else
PRINT "expected test directory" "warning"
fi
}
#=====================
# _CHECK_DOC_EXIST
#
# Check if module has doc structure in place.
#
#=====================
_CHECK_DOC_EXIST()
{
if [ -d "$_dir_name/doc" ]; then
if [ -f "$_dir_name/doc/index.md" ]; then
PRINT "OK" "ok"
else
PRINT "expected index.md in the doc directory " "warning"
fi
else
PRINT "expected doc directory" "warning"
fi
}
#=====================
# _CHECK_GITLABCI_FILE_EXISTS
#
# Check if module has gitlab-ci file present.
#
#=====================
_CHECK_GITLABCI_FILE_EXISTS()
{
if [ -f "$_dir_name/.gitlab-ci.yml" ]; then
PRINT "OK" "ok"
else
PRINT "expected .gitlab-ci.yml file" "warning"
fi
}
# Disable warning about local keyword usage
# shellcheck disable=SC2039
# Disable warning about indirectly checking status code
# shellcheck disable=SC2181
#=====================
# _CHECK_BASHISMS
#
# Check if module possibly has bashisms
#
#=====================
_CHECK_BASHISMS()
{
local _script_file_ext=
local _script_file=
if [ -f "Spacefile.sh" ]; then
_script_file="Spacefile.sh"
elif [ -f "Spacefile.bash" ]; then
_script_file="Spacefile.bash"
fi
_script_file_ext="${_script_file##*.}"
# checkbashisms
if [ "${_script_file_ext}" = "sh" ]; then
if command -v "checkbashisms" >/dev/null; then
checkbashisms -f "$_script_file" >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
PRINT "Possible bashisms found in $_script_file with checkbashisms" "warning"
fi
fi
fi
# run shellcheck
if command -v "shellcheck" >/dev/null; then
shellcheck --exclude=2148 --shell=${_script_file_ext} "$_script_file" >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
PRINT "Possible bashisms found in $_script_file with shellcheck" "warning"
fi
fi
}
#=====================
# _CHECK_MODULE
#
# Check if module complies with Space module guidelines.
#
# Parameters:
# $1: module directory path
#
# Returns:
# 0: success
# 1: failed. Directory path is not pointing to a module.
#
#=====================
_CHECK_MODULE()
{
# shellcheck disable=SC2034
SPACE_DEP="PRINT _CHECK_DEP_INSTALL_NODE _CHECK_LICENSE_FILE_EXISTS _CHECK_CHANGELOG_FILE_EXISTS _CHECK_README_FILE_EXISTS _CHECK_UPDATE_README_FILE_EXISTS _CHECK_STABLE_FILE_EXISTS _CHECK_REQUIREMENT_FILE_EXISTS _CHECK_TESTS_EXIST _CHECK_DOC_EXIST _CHECK_GITLABCI_FILE_EXISTS _CHECK_BASHISMS"
if [ "$#" -eq 0 ]; then
PRINT "missing module directory path to analyze" "error"
return 1
fi
# shellcheck disable=SC2039
local _dir_name="$1"
# Append PWD if path is relative
if [ ! "${_dir_name}" = "${_dir_name#/}" ]; then
_dir_name="${PWD}/${_dir_name}"
fi
# Check for Spacefile.sh|.bash,yaml
if [ -f "$_dir_name/Spacefile.yaml" ]; then
if [ -f "$_dir_name/Spacefile.sh" ] \
|| [ -f "$_dir_name/Spacefile.bash" ]; then
PRINT "OK" "ok"
_CHECK_DEP_INSTALL_NODE
_CHECK_LICENSE_FILE_EXISTS
_CHECK_CHANGELOG_FILE_EXISTS
_CHECK_README_FILE_EXISTS
_CHECK_UPDATE_README_FILE_EXISTS
_CHECK_STABLE_FILE_EXISTS
_CHECK_REQUIREMENT_FILE_EXISTS
_CHECK_TESTS_EXIST
_CHECK_DOC_EXIST
_CHECK_GITLABCI_FILE_EXISTS
_CHECK_BASHISMS
else
PRINT "expected Spacefile.sh|bash in directory: $_dir_name" "error"
exit 1
fi
else
PRINT "expected Spacefile.yaml in directory: $_dir_name" "error"
exit 1
fi
}