-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_mandatory_fields.sh
executable file
·53 lines (40 loc) · 1.11 KB
/
check_mandatory_fields.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
#!/bin/bash
#
# Copyright (c) 2018-2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
set -e
FIELDS=('displayName' 'description' 'projectType')
# check that field value, given in the parameter, is not null or empty
function check_field() {
if [[ $1 == "null" || $1 = "" ]];then
return 1;
fi
return 0
}
readarray -d '' arr < <(find "$1" -name 'meta.yaml' -print0)
for i in "${arr[@]}"
do
id=$(yq r "$i" displayName | sed 's/^"\(.*\)"$/\1/')
full_id=${id}:${i}
echo "Checking devfile '${i}'"
unset NULL_OR_EMPTY_FIELDS
for FIELD in "${FIELDS[@]}"
do
VALUE=$(yq r "$i" "$FIELD")
if ! check_field "${VALUE}";then
NULL_OR_EMPTY_FIELDS+="$FIELD "
fi
done
if [[ -n "${NULL_OR_EMPTY_FIELDS}" ]];then
echo "!!! Null or empty mandatory fields in '${full_id}': $NULL_OR_EMPTY_FIELDS"
INVALID_FIELDS=true
fi
done
if [[ -n "${INVALID_FIELDS}" ]];then
exit 1
fi