fix(ci): add error handling to release creation API calls
Some checks failed
Build and Test / build (push) Has been cancelled
Release Build / build-linux (push) Successful in 1h26m59s
Release Build / publish-release (push) Has been cancelled

Print HTTP status and response body on failure instead of crashing
with a cryptic KeyError when the Gitea API returns an error.
This commit is contained in:
forbes
2026-02-08 10:22:26 -06:00
parent 67f825c305
commit ee839c23b8

View File

@@ -393,21 +393,34 @@ jobs:
fi fi
# Create release # Create release
release_id=$(curl -s -X POST \ response=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \ -H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$PAYLOAD" \ -d "$PAYLOAD" \
"${GITEA_URL}/api/v1/repos/${REPO}/releases" | \ "${GITEA_URL}/api/v1/repos/${REPO}/releases")
python3 -c "import sys,json; print(json.load(sys.stdin)['id'])") http_code=$(echo "$response" | tail -1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then
echo "::error::Failed to create release (HTTP ${http_code}): ${body}"
exit 1
fi
release_id=$(echo "$body" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
echo "Created release ${release_id}" echo "Created release ${release_id}"
# Upload assets # Upload assets
for file in release/*; do for file in release/*; do
filename=$(basename "$file") filename=$(basename "$file")
echo "Uploading ${filename}..." echo "Uploading ${filename}..."
curl -s -X POST \ upload_resp=$(curl -s -w "\n%{http_code}" -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \ -H "Authorization: token ${GITEA_TOKEN}" \
-F "attachment=@${file}" \ -F "attachment=@${file}" \
"${GITEA_URL}/api/v1/repos/${REPO}/releases/${release_id}/assets?name=${filename}" "${GITEA_URL}/api/v1/repos/${REPO}/releases/${release_id}/assets?name=${filename}")
echo " done." upload_code=$(echo "$upload_resp" | tail -1)
if [ "$upload_code" -lt 200 ] || [ "$upload_code" -ge 300 ]; then
echo "::warning::Failed to upload ${filename} (HTTP ${upload_code})"
else
echo " done."
fi
done done