Skip to content

Commit 63ab28a

Browse files
committed
fix: use curl --upload-file instead of --data-binary for reliable uploads
--data-binary with @file can corrupt binary files during upload. --upload-file is the curl-recommended method for uploading files and preserves binary data correctly. Also fix response parsing to properly extract size from JSON body.
1 parent 6fb8d9a commit 63ab28a

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

.github/workflows/desktop-release.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,27 @@ jobs:
166166
fi
167167
168168
for attempt in 1 2 3; do
169+
# Use --upload-file which is designed for reliable binary uploads
169170
response=$(curl -s -w "\n%{http_code}" \
170171
-H "Authorization: token $GITHUB_TOKEN" \
171172
-H "Content-Type: application/octet-stream" \
172-
--data-binary "@$file" \
173+
--upload-file "$file" \
173174
"https://uploads.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=$filename")
174175
http_code=$(echo "$response" | tail -1)
175-
upload_size=$(echo "$response" | head -1 | jq -r '.size // 0')
176+
body=$(echo "$response" | sed '$d')
177+
uploaded_size=$(echo "$body" | jq -r '.size // 0')
176178
177-
if [ "$http_code" = "201" ] && [ "$upload_size" = "$filesize" ]; then
178-
echo " OK (verified: $upload_size bytes)"
179+
if [ "$http_code" = "201" ] && [ "$uploaded_size" = "$filesize" ]; then
180+
echo " OK (verified: $uploaded_size bytes)"
179181
break
180182
fi
181-
echo " Attempt $attempt: HTTP $http_code, uploaded $upload_size / expected $filesize"
183+
echo " Attempt $attempt: HTTP $http_code, uploaded=$uploaded_size expected=$filesize"
182184
# Clean up partial upload
183-
partial=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
185+
new_asset=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
184186
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets" \
185187
| jq -r ".[] | select(.name == \"$filename\") | .id")
186-
[ -n "$partial" ] && curl -s -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
187-
"https://api.github.com/repos/${{ github.repository }}/releases/assets/$partial"
188+
[ -n "$new_asset" ] && curl -s -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
189+
"https://api.github.com/repos/${{ github.repository }}/releases/assets/$new_asset"
188190
sleep 10
189191
done
190192
done

0 commit comments

Comments
 (0)