chore: fix sync to gitcode action retry logic (#11881)

This commit is contained in:
defi-failure 2025-12-13 22:51:11 +08:00 committed by GitHub
parent 5bd550bfb4
commit f0ec2354dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -216,6 +216,7 @@ jobs:
local filename=$(basename "$file") local filename=$(basename "$file")
local max_retries=3 local max_retries=3
local retry=0 local retry=0
local curl_status=0
echo "Uploading: $filename" echo "Uploading: $filename"
@ -224,34 +225,45 @@ jobs:
while [ $retry -lt $max_retries ]; do while [ $retry -lt $max_retries ]; do
# Get upload URL # Get upload URL
curl_status=0
UPLOAD_INFO=$(curl -s --connect-timeout 30 --max-time 60 \ UPLOAD_INFO=$(curl -s --connect-timeout 30 --max-time 60 \
-H "Authorization: Bearer ${GITCODE_TOKEN}" \ -H "Authorization: Bearer ${GITCODE_TOKEN}" \
"${API_URL}/repos/${GITCODE_OWNER}/${GITCODE_REPO}/releases/${TAG_NAME}/upload_url?file_name=${encoded_filename}") "${API_URL}/repos/${GITCODE_OWNER}/${GITCODE_REPO}/releases/${TAG_NAME}/upload_url?file_name=${encoded_filename}") || curl_status=$?
UPLOAD_URL=$(echo "$UPLOAD_INFO" | jq -r '.url // empty') if [ $curl_status -eq 0 ]; then
UPLOAD_URL=$(echo "$UPLOAD_INFO" | jq -r '.url // empty')
if [ -n "$UPLOAD_URL" ]; then if [ -n "$UPLOAD_URL" ]; then
# Write headers to temp file to avoid shell escaping issues # Write headers to temp file to avoid shell escaping issues
echo "$UPLOAD_INFO" | jq -r '.headers | to_entries[] | "header = \"" + .key + ": " + .value + "\""' > /tmp/upload_headers.txt echo "$UPLOAD_INFO" | jq -r '.headers | to_entries[] | "header = \"" + .key + ": " + .value + "\""' > /tmp/upload_headers.txt
# Upload file using PUT with headers from file # Upload file using PUT with headers from file
UPLOAD_RESPONSE=$(curl -s -w "\n%{http_code}" -X PUT \ curl_status=0
-K /tmp/upload_headers.txt \ UPLOAD_RESPONSE=$(curl -s -w "\n%{http_code}" -X PUT \
--data-binary "@${file}" \ -K /tmp/upload_headers.txt \
"$UPLOAD_URL") --data-binary "@${file}" \
"$UPLOAD_URL") || curl_status=$?
HTTP_CODE=$(echo "$UPLOAD_RESPONSE" | tail -n1) if [ $curl_status -eq 0 ]; then
RESPONSE_BODY=$(echo "$UPLOAD_RESPONSE" | sed '$d') HTTP_CODE=$(echo "$UPLOAD_RESPONSE" | tail -n1)
RESPONSE_BODY=$(echo "$UPLOAD_RESPONSE" | sed '$d')
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
echo " Uploaded: $filename" echo " Uploaded: $filename"
return 0 return 0
else
echo " Failed (HTTP $HTTP_CODE), retry $((retry + 1))/$max_retries"
echo " Response: $RESPONSE_BODY"
fi
else
echo " Upload request failed (curl exit $curl_status), retry $((retry + 1))/$max_retries"
fi
else else
echo " Failed (HTTP $HTTP_CODE), retry $((retry + 1))/$max_retries" echo " Failed to get upload URL, retry $((retry + 1))/$max_retries"
echo " Response: $RESPONSE_BODY" echo " Response: $UPLOAD_INFO"
fi fi
else else
echo " Failed to get upload URL, retry $((retry + 1))/$max_retries" echo " Failed to get upload URL (curl exit $curl_status), retry $((retry + 1))/$max_retries"
echo " Response: $UPLOAD_INFO" echo " Response: $UPLOAD_INFO"
fi fi