fix(release): surface the actual Gitea API error on mirror failure
Release desktop / bundle (push) Successful in 4m24s
Release desktop / bundle (push) Successful in 4m24s
The mirror step's release id came back empty on the last real run but nothing failed loudly — every curl response was swallowed (|| true, or piped straight to /dev/null), so we had no idea why. Capture HTTP status + response body on every call and exit 1 with the actual error instead of silently uploading to a malformed //assets URL with no release id.
This commit is contained in:
@@ -196,16 +196,22 @@ jobs:
|
|||||||
set -e
|
set -e
|
||||||
create_or_get_release() {
|
create_or_get_release() {
|
||||||
local mirror_tag="$1" prerelease="$2"
|
local mirror_tag="$1" prerelease="$2"
|
||||||
REL=$(curl -sS -X POST \
|
REL=$(curl -sS -w '\n%{http_code}' -X POST \
|
||||||
-H "Authorization: token ${TOKEN}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"tag_name\":\"${mirror_tag}\",\"name\":\"Parking System ${TAG}\",\"draft\":false,\"prerelease\":${prerelease}}" \
|
-d "{\"tag_name\":\"${mirror_tag}\",\"name\":\"Parking System ${TAG}\",\"draft\":false,\"prerelease\":${prerelease}}" \
|
||||||
"${API}/repos/${MIRROR_REPO}/releases" || true)
|
"${API}/repos/${MIRROR_REPO}/releases" || true)
|
||||||
|
echo "create response (${mirror_tag}): ${REL}"
|
||||||
REL_ID=$(printf '%s' "$REL" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
|
REL_ID=$(printf '%s' "$REL" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
|
||||||
if [ -z "$REL_ID" ]; then
|
if [ -z "$REL_ID" ]; then
|
||||||
REL_ID=$(curl -sS -H "Authorization: token ${TOKEN}" \
|
LOOKUP=$(curl -sS -w '\n%{http_code}' -H "Authorization: token ${TOKEN}" \
|
||||||
"${API}/repos/${MIRROR_REPO}/releases/tags/${mirror_tag}" \
|
"${API}/repos/${MIRROR_REPO}/releases/tags/${mirror_tag}")
|
||||||
| grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
|
echo "tag lookup response (${mirror_tag}): ${LOOKUP}"
|
||||||
|
REL_ID=$(printf '%s' "$LOOKUP" | grep -o '"id":[0-9]*' | head -1 | cut -d: -f2 || true)
|
||||||
|
fi
|
||||||
|
if [ -z "$REL_ID" ]; then
|
||||||
|
echo "::error::could not create or find release for tag ${mirror_tag} on ${MIRROR_REPO} — see responses above"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
upload_assets() {
|
upload_assets() {
|
||||||
@@ -213,11 +219,15 @@ jobs:
|
|||||||
for f in dist/*; do
|
for f in dist/*; do
|
||||||
name=$(basename "$f")
|
name=$(basename "$f")
|
||||||
echo "mirroring ${name} -> release ${rel_id}"
|
echo "mirroring ${name} -> release ${rel_id}"
|
||||||
curl -sS -X POST \
|
HTTP_CODE=$(curl -sS -o /tmp/upload_resp.json -w '%{http_code}' -X POST \
|
||||||
-H "Authorization: token ${TOKEN}" \
|
-H "Authorization: token ${TOKEN}" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: application/octet-stream" \
|
||||||
--data-binary @"${f}" \
|
--data-binary @"${f}" \
|
||||||
"${API}/repos/${MIRROR_REPO}/releases/${rel_id}/assets?name=${name}" >/dev/null
|
"${API}/repos/${MIRROR_REPO}/releases/${rel_id}/assets?name=${name}")
|
||||||
|
if [ "$HTTP_CODE" -ge 300 ]; then
|
||||||
|
echo "::error::upload of ${name} failed (HTTP ${HTTP_CODE}): $(cat /tmp/upload_resp.json)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user