Fix release JSON parsing: use python3 instead of grep
All checks were successful
Build & Release / build (push) Successful in 34s
All checks were successful
Build & Release / build (push) Successful in 34s
grep-based JSON parsing broke on Gitea's response format (exit 3: URL malformat from corrupted release ID). Use python3 json module for reliable parsing. Also add trap-based token cleanup and upload status verification. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -72,35 +72,35 @@ jobs:
|
|||||||
# resolvable from CI job containers (separate Docker network)
|
# resolvable from CI job containers (separate Docker network)
|
||||||
API="https://git.davoryn.de/api/v1"
|
API="https://git.davoryn.de/api/v1"
|
||||||
|
|
||||||
# Create release
|
cleanup_token() {
|
||||||
|
curl -s -X DELETE -u "calic:${TOKEN}" "${API}/users/calic/tokens/${TOKEN_NAME}" >/dev/null 2>&1 || true
|
||||||
|
}
|
||||||
|
trap cleanup_token EXIT
|
||||||
|
|
||||||
|
# Create release — use python3 for reliable JSON parsing
|
||||||
echo "Creating release ${TAG}..."
|
echo "Creating release ${TAG}..."
|
||||||
RELEASE_RESP=$(curl -s -w "\n%{http_code}" \
|
RELEASE_JSON=$(curl -s \
|
||||||
-H "Authorization: token ${TOKEN}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"Welcome Screen ${MOD_VERSION}\",\"body\":\"Release ${MOD_VERSION}\"}" \
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"Welcome Screen ${MOD_VERSION}\",\"body\":\"Release ${MOD_VERSION}\"}" \
|
||||||
"${API}/repos/calic/vs-welcome-screen/releases")
|
"${API}/repos/calic/vs-welcome-screen/releases")
|
||||||
HTTP_CODE=$(echo "$RELEASE_RESP" | tail -1)
|
|
||||||
RELEASE_BODY=$(echo "$RELEASE_RESP" | sed '$d')
|
|
||||||
|
|
||||||
if [ "$HTTP_CODE" -lt 200 ] || [ "$HTTP_CODE" -ge 300 ]; then
|
RELEASE_ID=$(echo "$RELEASE_JSON" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
|
||||||
echo "ERROR: Release creation failed (HTTP ${HTTP_CODE}): ${RELEASE_BODY}"
|
if [ -z "$RELEASE_ID" ]; then
|
||||||
# Clean up token before exiting
|
echo "ERROR: Failed to create release. Response: ${RELEASE_JSON}"
|
||||||
curl -s -X DELETE -u "calic:${TOKEN}" "${API}/users/calic/tokens/${TOKEN_NAME}" >/dev/null 2>&1 || true
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RELEASE_ID=$(echo "$RELEASE_BODY" | grep -oPm1 '"id":\K[0-9]+')
|
|
||||||
echo "Release created (id: ${RELEASE_ID})"
|
echo "Release created (id: ${RELEASE_ID})"
|
||||||
|
|
||||||
# Attach mod ZIP to release
|
# Attach mod ZIP to release
|
||||||
echo "Uploading ${MOD_ZIP}..."
|
echo "Uploading ${MOD_ZIP}..."
|
||||||
curl -sf \
|
UPLOAD_RESP=$(curl -s -w "\nHTTP_%{http_code}" \
|
||||||
-H "Authorization: token ${TOKEN}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-F "attachment=@${MOD_ZIP}" \
|
-F "attachment=@${MOD_ZIP}" \
|
||||||
"${API}/repos/calic/vs-welcome-screen/releases/${RELEASE_ID}/assets"
|
"${API}/repos/calic/vs-welcome-screen/releases/${RELEASE_ID}/assets")
|
||||||
|
if ! echo "$UPLOAD_RESP" | grep -q "HTTP_201"; then
|
||||||
|
echo "ERROR: Upload failed. Response: ${UPLOAD_RESP}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Release ${TAG} created with ${MOD_ZIP}"
|
echo "Release ${TAG} created with ${MOD_ZIP}"
|
||||||
|
|
||||||
# Clean up token
|
|
||||||
curl -s -X DELETE -u "calic:${TOKEN}" \
|
|
||||||
"${API}/users/calic/tokens/${TOKEN_NAME}" >/dev/null 2>&1 || true
|
|
||||||
|
|||||||
Reference in New Issue
Block a user