-
Notifications
You must be signed in to change notification settings - Fork 33
/
validate
executable file
·63 lines (54 loc) · 1.45 KB
/
validate
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
#!/bin/bash
#
# Validate tablet data
#
set -e -u -o pipefail
# Execute kwalify with document on stdin, overriding file name, appropriately
# directed output and appropriate exit status.
#
# Args: filename [kwalify_arg...]
# Stdout: successful output with overriden filename
# Stderr: error output with overriden filename
#
function kwalify_strict()
{
declare -r filename="$1"; shift
declare output
read -r -d '' output < <(
kwalify "$@"
) || true
if [[ $output == *[^A-Za-z]valid[^A-Za-z]* ]]; then
printf '%s\n' "${output//(stdin)/$filename}"
return 0
else
printf '%s\n' "${output//(stdin)/$filename}" >&2
return 1
fi
}
kwalify_strict schema.yml -m < schema.yml >/dev/null
declare passed=true
declare f
declare yaml
declare image_name
declare image_file
for f in */index.md; do
read -r -d '' yaml < <(
sed -ne '/^---$/,/^---$/ {/^---$/b; p}' "$f"
) || true
kwalify_strict "$f" -f schema.yml <<<"$yaml" >/dev/null ||
{ passed=false; continue; }
read -r -d '' image_name < <(
awk '/^\s*image:\s+/ {print $2}' <<<"$yaml"
) || true
if [ -z "$image_name" ]; then
printf "%s: image is not specified\\n" "$f" >&2
passed=false
continue
fi
image_file="${f%index.md}/${image_name}.jpg"
if ! [ -e "$image_file" ]; then
printf "%s: image doesn't exist: %s\\n" "$f" "$image_file" >&2
passed=false
fi
done
"$passed"