-
Notifications
You must be signed in to change notification settings - Fork 183
/
schema_check.sh
executable file
·91 lines (74 loc) · 2.72 KB
/
schema_check.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
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
#!/usr/bin/env bash
# This script does some minimal sanity checks of schema files.
# It expects to find a schema file for each version listed in CHANGELOG.md
# since 1.0.0 release.
set -e
BUILD_TOOL_SCHEMAS_VERSION=0.25.0
# List of versions that do not require or have a schema.
declare -a skip_versions=("1.0.0" "1.0.1" "1.1.0" "1.2.0" "1.3.0" "1.6.0")
# Verifies remote availability of a schema file.
#
# If the schema file is available for download, THEN we make sure it is exactly
# what is in the repository. If the file is not available for download,
# we pass this check. This is to allow releases to be checked in, where
# a new version is specified but hasn't propagated to the website yet.
#
# Args:
# 1 - version number
verify_remote_availability() {
local ver="$1"
echo -n "Ensure published schema file https://opentelemetry.io/schemas/$ver matches local copy... "
if curl --fail --no-progress-meter https://opentelemetry.io/schemas/$ver > verify$ver 2>/dev/null; then
diff verify$ver $file && echo "OK, matches" \
|| (echo "Incorrect!" && exit 3)
else
echo "Not found"
fi
rm verify$ver
}
# Verifies remote availability of a schema file in the current repository.
#
# Args:
# 1 - version number
verify_local_availability() {
local ver="$1"
file="$schemas_dir/$ver"
echo -n "Ensure schema file $file exists... "
# Check that the schema for the version exists.
if [ -f "$file" ]; then
echo "OK, exists."
else
echo "FAILED: $file does not exist. The schema file must exist because the version is declared in CHANGELOG.md."
exit 3
fi
}
root_dir=$PWD
schemas_dir=$root_dir/schemas
# Find all version sections in CHANGELOG that start with a number in 1..9 range.
grep -o -e '## v[1-9].*\s' $root_dir/CHANGELOG.md | grep -o '[1-9].*' | while read ver; do
if [[ " ${skip_versions[*]} " == *" $ver "* ]]; then
# Skip this version, it does not need a schema file.
continue
fi
verify_local_availability "$ver"
verify_remote_availability "$ver"
done
# Now check the content of all schema files in the ../schemas directory.
for file in $schemas_dir/*; do
# Filename is the version number.
ver=$(basename $file)
echo -n "Checking schema file $file for version $ver... "
# Check that the version is defined in the schema file.
if ! grep -q "\s$ver:" $file; then
echo "FAILED: $ver version definition is not found in $file"
exit 1
fi
# Check that the schema_url matches the version.
if ! grep -q "schema_url: https://opentelemetry.io/schemas/$ver" $file; then
echo "FAILED: schema_url is not found in $file"
exit 2
fi
docker run -v $schemas_dir:/schemas \
otel/build-tool-schemas:$BUILD_TOOL_SCHEMAS_VERSION --file /schemas/$ver --version=$ver
echo "OK"
done