Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/misc/scripts/validate_extension_api.sh
21066 views
1
#!/usr/bin/env bash
2
3
set -o pipefail
4
5
if [ ! -f "version.py" ]; then
6
echo "Warning: This script is intended to be run from the root of the Godot repository."
7
echo "Some of the paths checks may not work as intended from a different folder."
8
fi
9
10
if [ $# != 1 ]; then
11
echo "Usage: @0 <path-to-godot-executable>"
12
exit 1
13
fi
14
15
api_validation_dir="$( dirname -- "$( dirname -- "${BASH_SOURCE[0]//\.\//}" )" )/extension_api_validation/"
16
17
has_problems=0
18
warn_extra=0
19
reference_tag=""
20
expected_errors=""
21
22
make_annotation()
23
{
24
local title=$1
25
local body=$2
26
local type=$3
27
local file=$4
28
if [[ "$GITHUB_OUTPUT" == "" ]]; then
29
echo "$title"
30
echo "$body"
31
else
32
body="$(awk 1 ORS='%0A' - <<<"$body")"
33
echo "::$type file=$file,title=$title ::$body"
34
fi
35
}
36
37
get_expected_output()
38
{
39
local parts=()
40
IFS='_' read -ra parts <<< "$(basename "$1")"
41
42
if [[ "${#parts[@]}" == "2" ]]; then
43
while read -r file; do
44
cat "$file" >> "$expected_errors"
45
done <<< "$(find "$1" -type f -name "*.txt")"
46
47
next="$(find "$api_validation_dir" -type d -name "${parts[1]}*")"
48
if [[ "$next" != "" ]]; then
49
get_expected_output "$next"
50
fi
51
reference_tag="${parts[0]}"
52
warn_extra=0
53
else
54
while read -r file; do
55
cat "$file" >> "$expected_errors"
56
done <<< "$(find "$1" -type f -name "*.txt")"
57
58
reference_tag="${parts[0]}"
59
warn_extra=1
60
fi
61
}
62
63
while read -r dir; do
64
reference_file="$(mktemp)"
65
validate="$(mktemp)"
66
validation_output="$(mktemp)"
67
allowed_errors="$(mktemp)"
68
expected_errors="$(mktemp)"
69
get_expected_output "$dir"
70
71
# Download the reference extension_api.json
72
wget -nv --retry-on-http-error=503 --tries=5 --timeout=60 -cO "$reference_file" "https://raw.githubusercontent.com/godotengine/godot-headers/godot-$reference_tag/extension_api.json" || has_problems=1
73
# Validate the current API against the reference
74
"$1" --headless --validate-extension-api "$reference_file" 2>&1 | tee "$validate" | awk '!/^Validate extension JSON:/' - || true
75
# Collect the expected and actual validation errors
76
awk '/^Validate extension JSON:/' - < "$validate" | sort > "$validation_output"
77
awk '/^Validate extension JSON:/' - < "$expected_errors" | sort > "$allowed_errors"
78
79
# Differences between the expected and actual errors
80
new_validation_error="$(comm -23 "$validation_output" "$allowed_errors")"
81
obsolete_validation_error="$(comm -13 "$validation_output" "$allowed_errors")"
82
83
if [ -n "$obsolete_validation_error" ] && [ "$warn_extra" = "1" ]; then
84
#make_annotation "The following validation errors no longer occur (compared to $reference_tag):" "$obsolete_validation_error" warning "$file"
85
echo "The following validation errors no longer occur (compared to $reference_tag):"
86
echo "$obsolete_validation_error"
87
fi
88
if [ -n "$new_validation_error" ]; then
89
make_annotation "Compatibility to $reference_tag is broken in the following ways:" "$new_validation_error" error "$file"
90
has_problems=1
91
fi
92
93
rm -f "$reference_file" "$validate" "$validation_output" "$allowed_errors" "$expected_errors"
94
done <<< "$(find "$api_validation_dir" -type d -mindepth 1 -maxdepth 1)"
95
96
exit $has_problems
97
98