Path: blob/master/misc/scripts/validate_extension_api.sh
21066 views
#!/usr/bin/env bash12set -o pipefail34if [ ! -f "version.py" ]; then5echo "Warning: This script is intended to be run from the root of the Godot repository."6echo "Some of the paths checks may not work as intended from a different folder."7fi89if [ $# != 1 ]; then10echo "Usage: @0 <path-to-godot-executable>"11exit 112fi1314api_validation_dir="$( dirname -- "$( dirname -- "${BASH_SOURCE[0]//\.\//}" )" )/extension_api_validation/"1516has_problems=017warn_extra=018reference_tag=""19expected_errors=""2021make_annotation()22{23local title=$124local body=$225local type=$326local file=$427if [[ "$GITHUB_OUTPUT" == "" ]]; then28echo "$title"29echo "$body"30else31body="$(awk 1 ORS='%0A' - <<<"$body")"32echo "::$type file=$file,title=$title ::$body"33fi34}3536get_expected_output()37{38local parts=()39IFS='_' read -ra parts <<< "$(basename "$1")"4041if [[ "${#parts[@]}" == "2" ]]; then42while read -r file; do43cat "$file" >> "$expected_errors"44done <<< "$(find "$1" -type f -name "*.txt")"4546next="$(find "$api_validation_dir" -type d -name "${parts[1]}*")"47if [[ "$next" != "" ]]; then48get_expected_output "$next"49fi50reference_tag="${parts[0]}"51warn_extra=052else53while read -r file; do54cat "$file" >> "$expected_errors"55done <<< "$(find "$1" -type f -name "*.txt")"5657reference_tag="${parts[0]}"58warn_extra=159fi60}6162while read -r dir; do63reference_file="$(mktemp)"64validate="$(mktemp)"65validation_output="$(mktemp)"66allowed_errors="$(mktemp)"67expected_errors="$(mktemp)"68get_expected_output "$dir"6970# Download the reference extension_api.json71wget -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=172# Validate the current API against the reference73"$1" --headless --validate-extension-api "$reference_file" 2>&1 | tee "$validate" | awk '!/^Validate extension JSON:/' - || true74# Collect the expected and actual validation errors75awk '/^Validate extension JSON:/' - < "$validate" | sort > "$validation_output"76awk '/^Validate extension JSON:/' - < "$expected_errors" | sort > "$allowed_errors"7778# Differences between the expected and actual errors79new_validation_error="$(comm -23 "$validation_output" "$allowed_errors")"80obsolete_validation_error="$(comm -13 "$validation_output" "$allowed_errors")"8182if [ -n "$obsolete_validation_error" ] && [ "$warn_extra" = "1" ]; then83#make_annotation "The following validation errors no longer occur (compared to $reference_tag):" "$obsolete_validation_error" warning "$file"84echo "The following validation errors no longer occur (compared to $reference_tag):"85echo "$obsolete_validation_error"86fi87if [ -n "$new_validation_error" ]; then88make_annotation "Compatibility to $reference_tag is broken in the following ways:" "$new_validation_error" error "$file"89has_problems=190fi9192rm -f "$reference_file" "$validate" "$validation_output" "$allowed_errors" "$expected_errors"93done <<< "$(find "$api_validation_dir" -type d -mindepth 1 -maxdepth 1)"9495exit $has_problems969798