chore: improve meta.json validation with detailed error reporting and debug output

This commit is contained in:
Mauricio Siu 2025-04-03 00:38:14 -06:00
parent 38e0936ae5
commit 076c82490c

View File

@ -51,6 +51,9 @@ jobs:
- name: Validate meta.json structure and required fields
run: |
set -x # Enable debug mode to see all commands
exec 2>&1 # Redirect stderr to stdout to see all output
echo "🔍 Validating meta.json structure and required fields..."
# First check if meta.json exists and is valid JSON
@ -65,25 +68,28 @@ jobs:
fi
ERROR=0
ERRORS_FOUND=""
# Debug: Show total number of entries
TOTAL_ENTRIES=$(jq '. | length' meta.json)
echo "📊 Total entries in meta.json: $TOTAL_ENTRIES"
# Validate JSON structure and required fields
ENTRIES=$(jq -c '.[]' meta.json)
INDEX=0
while IFS= read -r entry; do
((INDEX++))
echo "-------------------------------------------"
echo "🔍 Checking entry #$INDEX..."
# Debug: Show the current entry
echo "Current entry: $entry" | jq '.'
# Get the ID for better error reporting
ID=$(echo "$entry" | jq -r '.id // "UNKNOWN"')
echo "📝 Processing entry with ID: $ID"
# Validate required top-level fields
for field in "id" "name" "version" "description" "logo" "links" "tags"; do
if [ "$(echo "$entry" | jq "has(\"$field\")")" != "true" ]; then
echo "❌ Entry #$INDEX is missing required field: $field"
ERROR_MSG="❌ Entry #$INDEX (ID: $ID) is missing required field: $field"
echo "$ERROR_MSG"
ERRORS_FOUND="$ERRORS_FOUND\n$ERROR_MSG"
ERROR=1
fi
done
@ -92,7 +98,9 @@ jobs:
if [ "$(echo "$entry" | jq 'has("links")')" == "true" ]; then
for link_field in "github" "website" "docs"; do
if [ "$(echo "$entry" | jq ".links | has(\"$link_field\")")" != "true" ]; then
echo "❌ Entry #$INDEX: links object is missing required field: $link_field"
ERROR_MSG="❌ Entry #$INDEX (ID: $ID): links object is missing required field: $link_field"
echo "$ERROR_MSG"
ERRORS_FOUND="$ERRORS_FOUND\n$ERROR_MSG"
ERROR=1
fi
done
@ -100,13 +108,17 @@ jobs:
# Validate tags array is not empty
if [ "$(echo "$entry" | jq '.tags | length')" -eq 0 ]; then
echo "❌ Entry #$INDEX: tags array cannot be empty"
ERROR_MSG="❌ Entry #$INDEX (ID: $ID): tags array cannot be empty"
echo "$ERROR_MSG"
ERRORS_FOUND="$ERRORS_FOUND\n$ERROR_MSG"
ERROR=1
fi
done <<< "$ENTRIES"
done < <(jq -c '.[]' meta.json)
echo "-------------------------------------------"
if [ $ERROR -eq 1 ]; then
echo "❌ meta.json structure validation failed."
echo -e "Summary of all errors found:$ERRORS_FOUND"
exit 1
else
echo "✅ meta.json structure validated successfully."