ci(release): keep the release payload valid JSON

The release body embedded literal newlines, so the create-release POST
was rejected; it only ever worked because an existing release was
found by tag. Escape the newlines, validate the payload, and print the
server responses when no release id can be resolved.
This commit is contained in:
faumaray committed 2026-12-06 15:10:45 +03:00
1 parent 6fe31ebf56
commit d0499c4cd7
1 file changed
+9 -2
+9 -2
View File
@@ -475,9 +475,11 @@ jobs:
(cd dist && sha256sum ./* > SHA256SUMS)
ls -l dist/
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
body="$(printf 'Release %s\n\nBuilt from %s with the full CTest suite green.\nSee SHA256SUMS for artifact digests.' "${tag}" "${GITHUB_SHA}")"
# Escaped newlines: the payload must stay valid JSON.
body="$(printf 'Release %s\\n\\nBuilt from %s with the full CTest suite green.\\nSee SHA256SUMS for artifact digests.' "${tag}" "${GITHUB_SHA}")"
payload="$(printf '{"tag_name":"%s","name":"%s","body":"%s","draft":false,"prerelease":false}' \
"${tag}" "${tag}" "${body}")"
printf '%s' "${payload}" | python3 -c 'import json,sys; json.load(sys.stdin)'
extract_id() {
python3 -c 'import json,sys; s=sys.stdin.read().strip(); print(json.loads(s).get("id","") if s else "")' 2>/dev/null || true
}
@@ -490,7 +492,12 @@ jobs:
"${api}/releases/tags/${tag}" || true)"
release_id="$(printf '%s' "${existing}" | extract_id)"
fi
test -n "${release_id}"
if [ -z "${release_id}" ]; then
echo "could not create or find the release for ${tag}:" >&2
echo "create: ${created}" >&2
echo "lookup: ${existing:-<none>}" >&2
exit 1
fi
for file in dist/*; do
name="$(basename "${file}")"
curl -fsS -X POST -H "Authorization: token ${TOKEN}" \