1
- #! /bin/bash
1
+ #! /usr/ bin/env bash
2
2
#
3
3
# This script serves to check YAML files in this repository that contain particular
4
4
# key fields where JSON string is expected. Such JSON strings are extracted and
10
10
# In case of the PR on GitHub, this check is tied to GitHub actions automatically,
11
11
# see `.github/workflows` directory.
12
12
13
- shopt -s globstar
13
+ if ! shopt -s globstar; then
14
+ echo " macOS ships bash-3.2 that does not know shopt -s globstar; install newer bash from homebrew"
15
+ exit 1
16
+ fi
17
+
18
+ # yq: `brew install yq` or `apt-get install yq`
19
+ # json_verify: `brew install yajl` or `apt-get install yajl-tools`
20
+ for dep in yq json_verify; do
21
+ if ! which -- ${dep} > /dev/null; then
22
+ echo " the dependency ${dep} is not installed; install it now"
23
+ exit 1
24
+ fi
25
+ done
14
26
15
27
function check_json() {
16
28
local f=" ${1} "
@@ -29,8 +41,9 @@ function check_json() {
29
41
echo " ${json} "
30
42
echo -n " > " ; echo " ${json} " | json_verify || ret_code=" ${?} "
31
43
done <<< " ${jsons}"
44
+ tmp_dir=$( mktemp --directory -t=check-jsons-in-file-)
32
45
else
33
- echo " Ignoring as this file doesn't contain necessary key field '${string} ' for check"
46
+ echo " Ignoring as this file doesn't contain necessary key field '${string} ' for check"
34
47
fi
35
48
36
49
return " ${ret_code} "
@@ -48,20 +61,27 @@ function split_yaml_file() {
48
61
return 0
49
62
}
50
63
51
- ret_code=0
64
+ function main() {
65
+ local ret_code=0
52
66
67
+ # Some yaml files can contain more definitions.
68
+ # This is a problem for `yq` tool so we need to split these into separate files.
69
+ local tmp_dir
70
+ tmp_dir=$( mktemp --directory -t check-json-XXXXXXXXXX-)
71
+ for f in ** /* .yaml; do
72
+ echo " Splitting the '${f} ' file."
73
+ split_yaml_file " ${f} " " ${tmp_dir} " || ret_code=" ${?} "
74
+ done
53
75
54
- # Some yaml files can contain more definitions.
55
- # This is a problem for `yq` tool so we need to split these into separate files.
56
- tmp_dir=$( mktemp --directory --suffix=-check-json)
57
- for f in ** /* .yaml; do
58
- echo " Splitting the '${f} ' file."
59
- split_yaml_file " ${f} " " ${tmp_dir} " || ret_code=" ${?} "
60
- done
76
+ for f in " ${tmp_dir} " /* ; do
77
+ check_json " ${f} " " opendatahub.io/notebook-software" || ret_code=" ${?} "
78
+ check_json " ${f} " " opendatahub.io/notebook-python-dependencies" || ret_code=" ${?} "
79
+ done
61
80
62
- for f in " ${tmp_dir} " /* ; do
63
- check_json " ${f} " " opendatahub.io/notebook-software" || ret_code=" ${?} "
64
- check_json " ${f} " " opendatahub.io/notebook-python-dependencies" || ret_code=" ${?} "
65
- done
81
+ exit " ${ret_code} "
82
+ }
66
83
67
- exit " ${ret_code} "
84
+ # allows sourcing the script into interactive session without executing it
85
+ if [[ " ${0} " == " ${BASH_SOURCE[0]} " ]]; then
86
+ main
87
+ fi
0 commit comments