ci(release): publish from the Pi; surface API 422s

Run 116 built both arches then POST /releases returned 422 six times
(--retry-all-errors) with no body, while sitting on docker-amd64 behind
android. Move publish to the Pi runner (same path as tag create) and
print the Forgejo error instead of retrying 4xx. README now matches the
core-only path filter and onionwire-ci-pi concurrency.
This commit is contained in:
Sirius DevOps 2026-09-12 02:51:07 -04:00
commit 9b7e72b257
No known key found for this signature in database
3 changed files with 69 additions and 31 deletions

View file

@ -12,26 +12,38 @@
# same-named assets instead of failing with 409.
set -euo pipefail
# Every API call goes through here. Publishing runs from CI containers that
# reach Forgejo through Cloudflare, where a bare HTTP/2 request intermittently
# dies with curl exit 92 (stream error) — retries plus forcing HTTP/1.1 make
# that a non-event.
# HTTP/1.1: Cloudflare resets HTTP/2 mid-POST (curl 92). Do NOT use
# --retry-all-errors: that retries 422 Unprocessable Entity five times
# and hides the response body (run 116). Connection failures still retry.
api_curl() {
curl -sS --http1.1 --retry 5 --retry-all-errors --retry-delay 3 \
curl -sS --http1.1 --retry 5 --retry-connrefused --retry-delay 3 \
--connect-timeout 20 --max-time 300 "$@"
}
auth_json() {
api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" -H "Content-Type: application/json" "$@"
}
tag="${1:?usage: publish-release.sh <tag> <name> <body-file> <asset>...}"
name="${2:?missing release name}"
body_file="${3:?missing body file}"
shift 3
: "${FORGEJO_TOKEN:?FORGEJO_TOKEN is not set}"
FORGEJO_TOKEN=$(printf '%s' "$FORGEJO_TOKEN" | tr -d '\r\n')
api="${REPO_API:-https://forgejo.siriusdevops.com/api/v1/repos/sirius/onionwire}"
target="${TARGET_COMMITISH:-}"
jqp() { python3 -c "import json,sys; d=json.load(sys.stdin); print($1)"; }
die_http() {
local what="$1" code="$2" file="$3"
echo "publish: $what HTTP $code" >&2
cat "$file" >&2 || true
echo >&2
exit 1
}
# Body with @TAG@ substituted, JSON-encoded by python (handles newlines/quotes).
python3 - "$body_file" "$tag" "$target" "$name" > /tmp/release-body.json <<'PY'
import json, sys
@ -50,24 +62,37 @@ if sys.argv[3]:
print(json.dumps(payload))
PY
code=$(api_curl -o /tmp/release-rel.json -w '%{http_code}' \
-H "Authorization: Bearer $FORGEJO_TOKEN" "$api/releases/tags/$tag")
code=$(auth_json -o /tmp/release-rel.json -w '%{http_code}' \
"$api/releases/tags/$tag")
if [ "$code" = "404" ]; then
echo "publish: creating release $tag"
api_curl -sf -X POST "$api/releases" \
-H "Authorization: Bearer $FORGEJO_TOKEN" \
-H 'Content-Type: application/json' \
--data @/tmp/release-body.json -o /tmp/release-rel.json
create=$(auth_json -o /tmp/release-rel.json -w '%{http_code}' \
-X POST --data-binary @/tmp/release-body.json "$api/releases")
if [ "$create" = "201" ]; then
:
elif [ "$create" = "409" ] || [ "$create" = "422" ]; then
echo "publish: POST releases HTTP $create — joining if the release exists"
cat /tmp/release-rel.json >&2 || true
echo >&2
code=$(auth_json -o /tmp/release-rel.json -w '%{http_code}' \
"$api/releases/tags/$tag")
if [ "$code" != "200" ]; then
die_http "create release $tag (then GET)" "$code" /tmp/release-rel.json
fi
echo "publish: release $tag exists, joining"
else
die_http "create release $tag" "$create" /tmp/release-rel.json
fi
elif [ "$code" = "200" ]; then
echo "publish: release $tag exists, updating"
rid=$(jqp "d['id']" < /tmp/release-rel.json)
api_curl -sf -X PATCH "$api/releases/$rid" \
-H "Authorization: Bearer $FORGEJO_TOKEN" \
-H 'Content-Type: application/json' \
--data @/tmp/release-body.json -o /tmp/release-rel.json
patch=$(auth_json -o /tmp/release-rel.json -w '%{http_code}' \
-X PATCH --data-binary @/tmp/release-body.json "$api/releases/$rid")
if [ "$patch" != "200" ]; then
die_http "PATCH release $rid" "$patch" /tmp/release-rel.json
fi
else
echo "publish: unexpected status $code from GET releases/tags/$tag" >&2
cat /tmp/release-rel.json >&2; exit 1
die_http "GET releases/tags/$tag" "$code" /tmp/release-rel.json
fi
rid=$(jqp "d['id']" < /tmp/release-rel.json)
echo "publish: release id $rid ($tag)"
@ -84,7 +109,7 @@ for f in "$@"; do
fi
asset=$(basename "$f")
echo "publish: asset $asset is $bytes bytes on disk"
api_curl -s -H "Authorization: Bearer $FORGEJO_TOKEN" "$api/releases/$rid/assets" \
api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \
| python3 -c "
import json,sys
for a in json.load(sys.stdin):
@ -92,13 +117,21 @@ for a in json.load(sys.stdin):
" | while read -r aid aname; do
if [ "$aname" = "$asset" ]; then
echo "publish: deleting stale asset $aname ($aid)"
api_curl -sf -X DELETE -H "Authorization: Bearer $FORGEJO_TOKEN" \
"$api/releases/$rid/assets/$aid" > /dev/null
del=$(api_curl -o /tmp/release-adel.json -w '%{http_code}' \
-X DELETE -H "Authorization: Bearer ${FORGEJO_TOKEN}" \
"$api/releases/$rid/assets/$aid")
if [ "$del" != "204" ] && [ "$del" != "404" ]; then
die_http "DELETE asset $aid" "$del" /tmp/release-adel.json
fi
fi
done
api_curl -sf -X POST "$api/releases/$rid/assets?name=$asset" \
-H "Authorization: Bearer $FORGEJO_TOKEN" \
-F "attachment=@$f" -o /tmp/release-asset.json
up=$(api_curl -o /tmp/release-asset.json -w '%{http_code}' \
-X POST "$api/releases/$rid/assets?name=$asset" \
-H "Authorization: Bearer ${FORGEJO_TOKEN}" \
-F "attachment=@$f")
if [ "$up" != "201" ]; then
die_http "upload $asset" "$up" /tmp/release-asset.json
fi
python3 -c "
import json,sys
d=json.load(open('/tmp/release-asset.json'))
@ -109,7 +142,7 @@ if not size:
"
done
api_curl -s -H "Authorization: Bearer $FORGEJO_TOKEN" "$api/releases/$rid/assets" \
api_curl -H "Authorization: Bearer ${FORGEJO_TOKEN}" "$api/releases/$rid/assets" \
| python3 -c "
import json,sys
for a in json.load(sys.stdin):