diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 882d7ec..41a564d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -134,10 +134,15 @@ jobs: fi AUTH="Authorization: token ${TOKEN}" - # Hinweis zu den Pipelines hier: kein "head -1" hinter curl/grep. - # Beendet sich das letzte Glied frueher, stirbt das erste an SIGPIPE - # und der Schritt bricht ab (pipefail). "grep -m1" auf einer Datei - # hat das Problem nicht. + # Zwei Fallstricke stecken in den Pipelines hier: + # - kein "head -1" hinter curl/grep: beendet sich das letzte Glied + # frueher, stirbt das erste an SIGPIPE und der Schritt bricht ab + # (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, # 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}")" RELEASE_ID="" 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 + case "${RELEASE_ID:-}" in + *[!0-9]*) RELEASE_ID="" ;; + esac + if [ -n "${RELEASE_ID:-}" ]; then echo "Release ${RELEASE_ID} vorhanden – wird aufgefrischt." CODE="$(curl -s -o /tmp/patch.json -w '%{http_code}' -X PATCH -H "$AUTH" \ @@ -195,7 +204,10 @@ jobs: -H 'Content-Type: application/json' \ -d "{\"tag_name\":\"${TAG}\",\"target_commitish\":\"${GITHUB_SHA}\",\"name\":\"${TITLE}\",\"body\":\"${BODY}\",\"draft\":false,\"prerelease\":${PRERELEASE}}" \ "${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 echo "Release konnte nicht angelegt werden (HTTP ${CODE}):" >&2 cat /tmp/release.json >&2 || true