From 076c82490c70e6d387235e7d3bd8bb0f2dfe7786 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Thu, 3 Apr 2025 00:38:14 -0600 Subject: [PATCH] chore: improve meta.json validation with detailed error reporting and debug output --- .github/workflows/validate.yml | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 1a56227..12a3545 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -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."