validate_extension_api.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. exit 1
  10. fi
  11. api_validation_dir="$( dirname -- "$( dirname -- "${BASH_SOURCE[0]//\.\//}" )" )/extension_api_validation/"
  12. has_problems=0
  13. warn_extra=0
  14. reference_tag=""
  15. expected_errors=""
  16. make_annotation()
  17. {
  18. local title=$1
  19. local body=$2
  20. local type=$3
  21. local file=$4
  22. if [[ "$GITHUB_OUTPUT" == "" ]]; then
  23. echo "$title"
  24. echo "$body"
  25. else
  26. body="$(awk 1 ORS='%0A' - <<<"$body")"
  27. echo "::$type file=$file,title=$title ::$body"
  28. fi
  29. }
  30. get_expected_output()
  31. {
  32. local parts=()
  33. IFS='_' read -ra parts <<< "$(basename -s .expected "$1")"
  34. if [[ "${#parts[@]}" == "2" ]]; then
  35. cat "$1" >> "$expected_errors"
  36. get_expected_output "$(find "$api_validation_dir" -name "${parts[1]}*.expected")"
  37. reference_tag="${parts[0]}"
  38. warn_extra=0
  39. else
  40. cat "$1" >> "$expected_errors"
  41. reference_tag="${parts[0]}"
  42. warn_extra=1
  43. fi
  44. }
  45. while read -r file; do
  46. reference_file="$(mktemp)"
  47. validate="$(mktemp)"
  48. validation_output="$(mktemp)"
  49. allowed_errors="$(mktemp)"
  50. expected_errors="$(mktemp)"
  51. get_expected_output "$file"
  52. # Download the reference extension_api.json
  53. wget -nv --retry-on-http-error=503 --tries=5 --timeout=60 -cO "$reference_file" "https://raw.githubusercontent.com/godotengine/godot-cpp/godot-$reference_tag/gdextension/extension_api.json" || has_problems=1
  54. # Validate the current API against the reference
  55. "$1" --headless --validate-extension-api "$reference_file" 2>&1 | tee "$validate" | awk '!/^Validate extension JSON:/' - || true
  56. # Collect the expected and actual validation errors
  57. awk '/^Validate extension JSON:/' - < "$validate" | sort > "$validation_output"
  58. awk '/^Validate extension JSON:/' - < "$expected_errors" | sort > "$allowed_errors"
  59. # Differences between the expected and actual errors
  60. new_validation_error="$(comm -23 "$validation_output" "$allowed_errors")"
  61. obsolete_validation_error="$(comm -13 "$validation_output" "$allowed_errors")"
  62. if [ -n "$obsolete_validation_error" ] && [ "$warn_extra" = "1" ]; then
  63. #make_annotation "The following validation errors no longer occur (compared to $reference_tag):" "$obsolete_validation_error" warning "$file"
  64. echo "The following validation errors no longer occur (compared to $reference_tag):"
  65. echo "$obsolete_validation_error"
  66. fi
  67. if [ -n "$new_validation_error" ]; then
  68. make_annotation "Compatibility to $reference_tag is broken in the following ways:" "$new_validation_error" error "$file"
  69. has_problems=1
  70. fi
  71. rm -f "$reference_file" "$validate" "$validation_output" "$allowed_errors" "$expected_errors"
  72. done <<< "$(find "$api_validation_dir" -name "*.expected")"
  73. exit $has_problems