@@ -142,20 +142,58 @@ jobs:
142142
143143 **Critical**: Output ONLY the JSON object, nothing else. The JSON will be parsed and validated.
144144
145- - name : Extract Result from Structured Output
145+ - name : Extract Result with Fallback
146146 id : extract
147147 env :
148148 STRUCTURED_OUTPUT : ${{ steps.analysis.outputs.structured_output }}
149+ EXECUTION_FILE : ${{ steps.analysis.outputs.execution_file }}
149150 run : |
150- if [ -z "$STRUCTURED_OUTPUT" ]; then
151- echo "No structured output returned from Claude"
151+ # Try to use structured_output first (preferred method)
152+ if [ -n "$STRUCTURED_OUTPUT" ] && [ "$STRUCTURED_OUTPUT" != "null" ]; then
153+ echo "✅ Using structured_output from claude-code-action"
154+ RESULT="$STRUCTURED_OUTPUT"
155+ else
156+ echo "⚠️ structured_output not available, falling back to execution file parsing"
157+
158+ if [ ! -f "$EXECUTION_FILE" ]; then
159+ echo "❌ Execution file not found: $EXECUTION_FILE"
160+ exit 1
161+ fi
162+
163+ # Debug: Show what messages we have
164+ echo "Messages in execution file:"
165+ jq -r '.[] | " - type: \(.type), subtype: \(.subtype // "none")"' < "$EXECUTION_FILE" || echo "Failed to parse execution file"
166+
167+ # Try to extract from StructuredOutput tool call as fallback
168+ echo "Attempting to extract from StructuredOutput tool call..."
169+ RESULT=$(jq -r '
170+ .[] |
171+ select(.type == "assistant") |
172+ .message.content[] |
173+ select(.type == "tool_use" and .name == "StructuredOutput") |
174+ .input |
175+ @json
176+ ' < "$EXECUTION_FILE" | head -1)
177+
178+ if [ -z "$RESULT" ] || [ "$RESULT" = "null" ]; then
179+ echo "❌ Could not extract structured output from any source"
180+ echo "Execution file contents:"
181+ cat "$EXECUTION_FILE"
182+ exit 1
183+ fi
184+
185+ echo "✅ Extracted from StructuredOutput tool call"
186+ fi
187+
188+ # Validate the result is valid JSON
189+ if ! echo "$RESULT" | jq -e . > /dev/null 2>&1; then
190+ echo "❌ Result is not valid JSON: $RESULT"
152191 exit 1
153192 fi
154193
155- # The structured_output is already in JSON format matching our schema
156194 {
157195 echo "result<<EOF"
158- echo "$STRUCTURED_OUTPUT "
196+ echo "$RESULT "
159197 echo "EOF"
160198 } >> "$GITHUB_OUTPUT"
161199
0 commit comments