@@ -54,36 +54,45 @@ jobs:
54
54
echo "Description: $description"
55
55
echo "URL: $url"
56
56
echo "Method: $method"
57
- echo "Data: $data"
58
- echo "==========================="
59
57
60
- response=$(curl -s -w "\n%{http_code}" \
58
+ # Store response in a temporary file to avoid string manipulation issues
59
+ local temp_file=$(mktemp)
60
+ local http_code=$(curl -s -w "%{http_code}" \
61
61
--request "$method" "$url" \
62
62
--header "Authorization: Bearer ${{ steps.bytebase-login.outputs.token }}" \
63
63
--header "Content-Type: application/json" \
64
- --data "$data")
65
-
66
- status_code=$(echo "$response" | tail -n1)
67
- body=$(echo "$response" | sed '$d')
64
+ --data "$data" \
65
+ -o "$temp_file")
68
66
69
- echo "=== DEBUG: Parsed Response ==="
70
- echo "Status code: $status_code"
71
- echo "Body length: ${#body}"
72
- echo "Body content:"
73
- echo "$body"
67
+ echo "=== DEBUG: Response Details ==="
68
+ echo "HTTP Status: $http_code"
69
+ echo "Response body:"
70
+ cat "$temp_file"
74
71
echo "==========================="
75
72
76
- if [[ $status_code -lt 200 || $status_code -ge 300 ]]; then
77
- echo "Error: Failed $description. Status: $status_code"
73
+ if [[ $http_code -lt 200 || $http_code -ge 300 ]]; then
74
+ echo "Error: Failed $description. Status: $http_code"
75
+ rm "$temp_file"
78
76
return 1
79
77
fi
80
78
81
- if [[ -z "$body" ]]; then
82
- echo "Error: Empty response body"
79
+ # Validate JSON response
80
+ if ! python3 -c "
81
+ import sys, json
82
+ try :
83
+ with open('$temp_file', 'r') as f :
84
+ json.load(f)
85
+ except json.JSONDecodeError as e :
86
+ print(f'Invalid JSON : {str(e)}', file=sys.stderr)
87
+ sys.exit(1)
88
+ " 2>/dev/null; then
89
+ echo " Error: Invalid JSON response"
90
+ rm "$temp_file"
83
91
return 1
84
92
fi
85
93
86
- echo "$body"
94
+ cat "$temp_file"
95
+ rm "$temp_file"
87
96
return 0
88
97
}
89
98
0 commit comments