2
0

validate_extension_api.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. set -o pipefail
  3. if [ ! -f "version.py" ]; then
  4. echo "Warning: This script is intended to be run from the root of the Godot repository."
  5. echo "Some of the paths checks may not work as intended from a different folder."
  6. fi
  7. if [ $# != 1 ]; then
  8. echo "Usage: @0 <path-to-godot-executable>"
  9. fi
  10. has_problems=0
  11. make_annotation()
  12. {
  13. local title=$1
  14. local body=$2
  15. local type=$3
  16. local file=$4
  17. if [[ "$GITHUB_OUTPUT" == "" ]]; then
  18. echo "$title"
  19. echo "$body"
  20. else
  21. body="$(awk 1 ORS='%0A' - <<<"$body")"
  22. echo "::$type file=$file,title=$title ::$body"
  23. fi
  24. }
  25. while read -r file; do
  26. reference_file="$(mktemp)"
  27. validate="$(mktemp)"
  28. validation_output="$(mktemp)"
  29. allowed_errors="$(mktemp)"
  30. # Download the reference extension_api.json
  31. reference_tag="$(basename -s .expected "$file")"
  32. wget -qcO "$reference_file" "https://raw.githubusercontent.com/godotengine/godot-cpp/godot-$reference_tag/gdextension/extension_api.json"
  33. # Validate the current API against the reference
  34. "$1" --headless --validate-extension-api "$reference_file" 2>&1 | tee "$validate" | awk '!/^Validate extension JSON:/' - || true
  35. # Collect the expected and actual validation errors
  36. awk '/^Validate extension JSON:/' - < "$validate" | sort > "$validation_output"
  37. awk '/^Validate extension JSON:/' - < "$file" | sort > "$allowed_errors"
  38. # Differences between the expected and actual errors
  39. new_validation_error="$(comm -23 "$validation_output" "$allowed_errors")"
  40. obsolete_validation_error="$(comm -13 "$validation_output" "$allowed_errors")"
  41. if [ -n "$obsolete_validation_error" ]; then
  42. make_annotation "The following validation errors no longer occur (compared to $reference_tag):" "$obsolete_validation_error" warning "$file"
  43. fi
  44. if [ -n "$new_validation_error" ]; then
  45. make_annotation "Compatibility to $reference_tag is broken in the following ways:" "$new_validation_error" error "$file"
  46. has_problems=1
  47. fi
  48. rm -f "$reference_file" "$validate" "$validation_output" "$allowed_errors"
  49. done <<< "$(find "$( dirname -- "$( dirname -- "${BASH_SOURCE[0]//\.\//}" )" )/extension_api_validation/" -name "*.expected")"
  50. exit $has_problems