@@ -44,44 +44,63 @@ jobs:
4444 response=$(curl -s -H "Authorization: Bearer $TOKEN" "$API_BASE/")
4545 echo "🔍 GET response:"
4646 echo "$response" | jq . || true
47-
4847 # 4. Collect changed JSON files and build payload
49- - name : 📁 Collect changed JSON files
48+ - name : 📁 Collect & inspect changed JSON files
5049 id : prepare_json_files
5150 run : |
51+ echo "🔍 Finding changed JSON files..."
5252 BASE="origin/${{ github.event.pull_request.base.ref }}"
5353 HEAD="${{ github.event.pull_request.head.sha }}"
54- mapfile -t files < <(git diff --name-only "$BASE" "$HEAD" | grep '\.json$')
54+ echo "Base: $BASE"
55+ echo "Head: $HEAD"
56+
57+ # List all changed files
58+ all_changed=$(git diff --name-only "$BASE" "$HEAD")
59+ echo "🔁 All changed files:"
60+ echo "$all_changed"
61+
62+ # Filter for .json
63+ mapfile -t files < <(echo "$all_changed" | grep '\.json$' || true)
64+ echo "🧾 JSON files to process (${#files[@]}): ${files[*]:-<none>}"
65+
5566 json_array="["
5667 for file in "${files[@]}"; do
57- if [ -f "$file" ] && jq -e . "$file" > /dev/null; then
58- content=$(jq -c . < "$file")
59- json_array+="{\"filename\":\"$file\",\"content\":$content},"
68+ echo "📄 Checking file: $file"
69+ if [ -f "$file" ]; then
70+ if jq -e . "$file" > /dev/null 2>&1; then
71+ content=$(jq -c . < "$file")
72+ json_array+="{\"filename\":\"$file\",\"content\":$content},"
73+ else
74+ echo "❌ Invalid JSON in $file, skipping"
75+ fi
76+ else
77+ echo "⚠️ File not found on disk: $file"
6078 fi
6179 done
6280 json_array="${json_array%,}]"
81+ echo "✅ Final JSON array:"
82+ echo "$json_array"
6383 echo "$json_array" > files_payload.json
84+
85+ # Export path
6486 echo "JSON_PAYLOAD_PATH=files_payload.json" >> $GITHUB_ENV
87+ echo "✅ Payload saved to files_payload.json (size: $(wc -c < files_payload.json) bytes)"
6588
6689 # 5. Send POST request with JSON payload to "/"
6790 - name : 🚀 Send POST request with JSON payload to root
6891 run : |
6992 echo "🚀 POST $API_BASE/"
70-
71- # Debug: show the payload before sending
72- echo "📄 Payload to send:"
73- cat "$JSON_PAYLOAD_PATH"
93+ echo "📄 Payload contents:"
94+ cat "$JSON_PAYLOAD_PATH" || { echo "❌ files_payload.json not found"; exit 1; }
7495 echo
75-
76- # Perform the POST, capturing both body and status
96+
7797 response=$(curl -s -w "\n%{http_code}" -X POST "$API_BASE/" \
7898 -H "Authorization: Bearer $TOKEN" \
7999 -H "Content-Type: application/json" \
80100 --data @"$JSON_PAYLOAD_PATH")
81-
101+
82102 body=$(echo "$response" | head -n -1)
83103 status_code=$(echo "$response" | tail -n1)
84-
85104 echo "🌐 HTTP status: $status_code"
86105 echo "🌐 Response body:"
87106 echo "$body" | jq . || true
90109 echo "❌ POST failed (HTTP $status_code)"
91110 exit 1
92111 fi
93-
94112 result_status=$(jq -r '.status' <<< "$body")
95113 result_message=$(jq -r '.message' <<< "$body")
96114 if [ "$result_status" != "passed" ]; then
0 commit comments