Merge pull request 'Release-ID richtig auslesen: grep -m1 begrenzt Zeilen, nicht Treffer' (#16) from ci/release-id-parse into main
All checks were successful
CI / PHP Lint (push) Successful in 36s
CI / PHP Lint-1 (push) Successful in 49s
Release-Paket / ZIP bauen und veröffentlichen (push) Successful in 11s
CI / Unit Tests & Static Analysis (push) Successful in 42s

This commit is contained in:
Friederich Loheide 2026-09-24 19:51:13 +00:00
commit 78819c0c96

View file

@ -134,10 +134,15 @@ jobs:
fi fi
AUTH="Authorization: token ${TOKEN}" AUTH="Authorization: token ${TOKEN}"
# Hinweis zu den Pipelines hier: kein "head -1" hinter curl/grep. # Zwei Fallstricke stecken in den Pipelines hier:
# Beendet sich das letzte Glied frueher, stirbt das erste an SIGPIPE # - kein "head -1" hinter curl/grep: beendet sich das letzte Glied
# und der Schritt bricht ab (pipefail). "grep -m1" auf einer Datei # frueher, stirbt das erste an SIGPIPE und der Schritt bricht ab
# hat das Problem nicht. # (pipefail).
# - "grep -m1" begrenzt auf die erste ZEILE, nicht auf den ersten
# Treffer. Die API antwortet einzeilig, deshalb erst mit tr an den
# Kommas umbrechen - sonst liefert die ID-Suche alle IDs des
# Dokuments auf einmal (Release, Autor, Anhaenge).
id_von() { tr ',' '\n' < "$1" | grep -m1 -o '"id":[0-9]*' | cut -d: -f2 || true; }
# Release-Text bewusst ohne Anfuehrungszeichen und Backslashes, # Release-Text bewusst ohne Anfuehrungszeichen und Backslashes,
# damit er ohne jq direkt in den JSON-Body passt (\n bleibt literal). # damit er ohne jq direkt in den JSON-Body passt (\n bleibt literal).
@ -168,9 +173,13 @@ jobs:
CODE="$(curl -s -o /tmp/release.json -w '%{http_code}' -H "$AUTH" "${API}/releases/tags/${TAG}")" CODE="$(curl -s -o /tmp/release.json -w '%{http_code}' -H "$AUTH" "${API}/releases/tags/${TAG}")"
RELEASE_ID="" RELEASE_ID=""
if [ "$CODE" = "200" ]; then if [ "$CODE" = "200" ]; then
RELEASE_ID="$(grep -m1 -o '"id":[0-9]*' /tmp/release.json | cut -d: -f2 || true)" RELEASE_ID="$(id_von /tmp/release.json)"
fi fi
case "${RELEASE_ID:-}" in
*[!0-9]*) RELEASE_ID="" ;;
esac
if [ -n "${RELEASE_ID:-}" ]; then if [ -n "${RELEASE_ID:-}" ]; then
echo "Release ${RELEASE_ID} vorhanden – wird aufgefrischt." echo "Release ${RELEASE_ID} vorhanden – wird aufgefrischt."
CODE="$(curl -s -o /tmp/patch.json -w '%{http_code}' -X PATCH -H "$AUTH" \ CODE="$(curl -s -o /tmp/patch.json -w '%{http_code}' -X PATCH -H "$AUTH" \
@ -195,7 +204,10 @@ jobs:
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
-d "{\"tag_name\":\"${TAG}\",\"target_commitish\":\"${GITHUB_SHA}\",\"name\":\"${TITLE}\",\"body\":\"${BODY}\",\"draft\":false,\"prerelease\":${PRERELEASE}}" \ -d "{\"tag_name\":\"${TAG}\",\"target_commitish\":\"${GITHUB_SHA}\",\"name\":\"${TITLE}\",\"body\":\"${BODY}\",\"draft\":false,\"prerelease\":${PRERELEASE}}" \
"${API}/releases")" "${API}/releases")"
RELEASE_ID="$(grep -m1 -o '"id":[0-9]*' /tmp/release.json | cut -d: -f2 || true)" RELEASE_ID="$(id_von /tmp/release.json)"
case "${RELEASE_ID:-}" in
*[!0-9]*) RELEASE_ID="" ;;
esac
if [ "$CODE" != "201" ] || [ -z "${RELEASE_ID:-}" ]; then if [ "$CODE" != "201" ] || [ -z "${RELEASE_ID:-}" ]; then
echo "Release konnte nicht angelegt werden (HTTP ${CODE}):" >&2 echo "Release konnte nicht angelegt werden (HTTP ${CODE}):" >&2
cat /tmp/release.json >&2 || true cat /tmp/release.json >&2 || true