Skip to content

Commit e691c37

Browse files
put back temp file
1 parent 972535f commit e691c37

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

.github/workflows/bb-export.yml

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,50 @@ jobs:
4949
local data="$3"
5050
local description="$4"
5151
52-
echo "Calling API: $description"
52+
echo "=== DEBUG: API Call Details ==="
53+
echo "Description: $description"
54+
echo "URL: $url"
55+
echo "Method: $method"
56+
echo "Data: $data"
5357
54-
# Store response in a temporary file
5558
temp_file=$(mktemp)
56-
57-
# Execute curl with minimal output
58-
response=$(curl -s \
59+
http_code=$(curl -v -s -w "%{http_code}" \
5960
--request "$method" "$url" \
6061
--header "Authorization: Bearer ${{ steps.bytebase-login.outputs.token }}" \
6162
--header "Content-Type: application/json" \
6263
--data "$data" \
63-
--write-out "\n%{http_code}" \
64-
2>/dev/null)
65-
66-
http_code=$(echo "$response" | tail -n1)
67-
body=$(echo "$response" | sed '$d')
64+
-o "$temp_file" 2>&1)
6865
69-
echo "Status code: $http_code"
66+
echo "=== DEBUG: Response Details ==="
67+
echo "HTTP Status: $http_code"
68+
echo "Response body:"
69+
cat "$temp_file"
70+
echo "==========================="
7071
7172
if [[ $http_code -lt 200 || $http_code -ge 300 ]]; then
72-
echo "Error: Failed $description"
73-
echo "Response: $body"
73+
echo "Error: Failed $description. Status: $http_code"
74+
cat "$temp_file"
75+
rm "$temp_file"
76+
return 1
77+
fi
78+
79+
if [[ ! -s "$temp_file" ]]; then
80+
echo "Error: Empty response from server"
81+
rm "$temp_file"
82+
return 1
83+
fi
84+
85+
# Simple one-line JSON validation
86+
if ! python3 -c "import json,sys; json.load(open('$temp_file'))" 2>/dev/null; then
87+
echo "Error: Invalid JSON response"
88+
echo "Response content:"
89+
cat "$temp_file"
90+
rm "$temp_file"
7491
return 1
7592
fi
7693
94+
cat "$temp_file"
95+
rm "$temp_file"
7796
return 0
7897
}
7998
@@ -117,38 +136,38 @@ jobs:
117136
118137
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
119138
echo "Processing $file"
120-
SQL_CONTENT=$(cat "$file" | python3 -c "import sys,base64,json; content=sys.stdin.read(); encoded=base64.b64encode(content.encode()).decode(); print(json.dumps(encoded)[1:-1])")
139+
SQL_CONTENT=$(base64 < "$file")
121140
echo "SQL_CONTENT=$SQL_CONTENT" >> $GITHUB_ENV
122141
STEP_ID=$(python3 -c "import uuid; print(str(uuid.uuid4()))")
123142
echo "STEP_ID=$STEP_ID" >> $GITHUB_ENV
124143
BASE_URL="${{ steps.bytebase-login.outputs.api_url }}"
125-
echo "BASE_URL111=$BASE_URL"
144+
echo "BASE_URL1111=$BASE_URL"
126145
echo "BASE_URL=$BASE_URL" >> $GITHUB_ENV
127146
128147
sheet_data=$(call_api \
129-
"$BASE_URL/projects/$PROJECT/sheets" \
148+
"$BASE_URL/v1/projects/$PROJECT/sheets" \
130149
"POST" \
131150
"{\"title\":\"\",\"content\":\"$SQL_CONTENT\",\"type\":\"TYPE_SQL\",\"source\":\"SOURCE_BYTEBASE_ARTIFACT\",\"visibility\":\"VISIBILITY_PUBLIC\"}" \
132151
"Create Sheet")
133152
134153
SHEET_NAME=$(echo "$sheet_data" | python3 -c "import sys, json; print(json.load(sys.stdin)['name'])")
135154
136155
plan_data=$(call_api \
137-
"$BASE_URL/projects/$PROJECT/plans" \
156+
"$BASE_URL/v1/projects/$PROJECT/plans" \
138157
"POST" \
139158
"{\"steps\":[{\"specs\":[{\"id\":\"$STEP_ID\",\"export_data_config\":{\"target\":\"/instances/$INSTANCE/databases/$DATABASE\",\"format\":\"$FORMAT\",\"sheet\":\"$SHEET_NAME\"}}]}],\"title\":\"Export data from $DATABASE\",\"description\":\"EXPORT\"}" \
140159
"Create Plan")
141160
142161
PLAN_NAME=$(echo "$plan_data" | python3 -c "import sys, json; print(json.load(sys.stdin)['name'])")
143162
144163
issue_data=$(call_api \
145-
"$BASE_URL/projects/$PROJECT/issues" \
164+
"$BASE_URL/v1/projects/$PROJECT/issues" \
146165
"POST" \
147166
"{\"approvers\":[],\"approvalTemplates\":[],\"subscribers\":[],\"title\":\"Issue: Export data from instances/$INSTANCE/databases/$DATABASE\",\"description\":\"SQL request from GitHub\",\"type\":\"DATABASE_DATA_EXPORT\",\"assignee\":\"\",\"plan\":\"$PLAN_NAME\"}" \
148167
"Create Issue")
149168
150169
rollout_data=$(call_api \
151-
"$BASE_URL/projects/$PROJECT/rollouts" \
170+
"$BASE_URL/v1/projects/$PROJECT/rollouts" \
152171
"POST" \
153172
"{\"plan\":\"$PLAN_NAME\"}" \
154173
"Create Rollout")

0 commit comments

Comments
 (0)