Refactor: Verwendung von jq zur präziseren ID-Extraktion aus JSON-Responses mit Fallback auf grep

This commit is contained in:
2026-08-23 13:09:27 +02:00
parent 837eab18b0
commit 589d0f6be1
2 changed files with 8 additions and 8 deletions
+4 -4
View File
@@ -97,7 +97,7 @@ jobs:
RELEASE_ID="" RELEASE_ID=""
if [ "$HTTP_CODE" -eq 200 ]; then if [ "$HTTP_CODE" -eq 200 ]; then
RELEASE_ID=$(echo "$BODY" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2) RELEASE_ID=$(echo "$BODY" | jq -r '.id // empty' 2>/dev/null || echo "$BODY" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
echo "Bestehendes Release gefunden (ID: ${RELEASE_ID})." echo "Bestehendes Release gefunden (ID: ${RELEASE_ID})."
else else
echo "Erstelle neues Preview-Release ${TAG_NAME}..." echo "Erstelle neues Preview-Release ${TAG_NAME}..."
@@ -117,7 +117,7 @@ jobs:
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$CREATE_PAYLOAD" \ -d "$CREATE_PAYLOAD" \
"${GITEA_URL}/api/v1/repos/${REPO}/releases") "${GITEA_URL}/api/v1/repos/${REPO}/releases")
RELEASE_ID=$(echo "$CREATE_RESP" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2) RELEASE_ID=$(echo "$CREATE_RESP" | jq -r '.id // empty' 2>/dev/null || echo "$CREATE_RESP" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
echo "Neues Preview-Release erstellt (ID: ${RELEASE_ID})." echo "Neues Preview-Release erstellt (ID: ${RELEASE_ID})."
fi fi
@@ -135,8 +135,8 @@ jobs:
filename="$(basename "$file")" filename="$(basename "$file")"
echo "Lade Release-Asset hoch: $filename" echo "Lade Release-Asset hoch: $filename"
ASSET_ID=$(echo "$EXISTING_ASSETS_JSON" | grep -B2 "\"name\":\"${filename}\"" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2 || true) ASSET_ID=$(echo "$EXISTING_ASSETS_JSON" | jq -r --arg name "$filename" '.[]? | select(.name == $name) | .id' 2>/dev/null | head -n1 || true)
if [ -n "$ASSET_ID" ]; then if [ -n "$ASSET_ID" ] && [ "$ASSET_ID" != "null" ]; then
echo "Lösche altes Asset mit ID ${ASSET_ID}..." echo "Lösche altes Asset mit ID ${ASSET_ID}..."
curl -s -X DELETE \ curl -s -X DELETE \
-H "Authorization: token ${TOKEN}" \ -H "Authorization: token ${TOKEN}" \
+4 -4
View File
@@ -97,7 +97,7 @@ jobs:
RELEASE_ID="" RELEASE_ID=""
if [ "$HTTP_CODE" -eq 200 ]; then if [ "$HTTP_CODE" -eq 200 ]; then
RELEASE_ID=$(echo "$BODY" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2) RELEASE_ID=$(echo "$BODY" | jq -r '.id // empty' 2>/dev/null || echo "$BODY" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
echo "Bestehendes Release gefunden (ID: ${RELEASE_ID})." echo "Bestehendes Release gefunden (ID: ${RELEASE_ID})."
else else
echo "Erstelle neues Release ${TAG_NAME}..." echo "Erstelle neues Release ${TAG_NAME}..."
@@ -117,7 +117,7 @@ jobs:
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$CREATE_PAYLOAD" \ -d "$CREATE_PAYLOAD" \
"${GITEA_URL}/api/v1/repos/${REPO}/releases") "${GITEA_URL}/api/v1/repos/${REPO}/releases")
RELEASE_ID=$(echo "$CREATE_RESP" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2) RELEASE_ID=$(echo "$CREATE_RESP" | jq -r '.id // empty' 2>/dev/null || echo "$CREATE_RESP" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2)
echo "Neues Release erstellt (ID: ${RELEASE_ID})." echo "Neues Release erstellt (ID: ${RELEASE_ID})."
fi fi
@@ -135,8 +135,8 @@ jobs:
filename="$(basename "$file")" filename="$(basename "$file")"
echo "Lade Release-Asset hoch: $filename" echo "Lade Release-Asset hoch: $filename"
ASSET_ID=$(echo "$EXISTING_ASSETS_JSON" | grep -B2 "\"name\":\"${filename}\"" | grep -o '"id":[0-9]*' | head -n1 | cut -d: -f2 || true) ASSET_ID=$(echo "$EXISTING_ASSETS_JSON" | jq -r --arg name "$filename" '.[]? | select(.name == $name) | .id' 2>/dev/null | head -n1 || true)
if [ -n "$ASSET_ID" ]; then if [ -n "$ASSET_ID" ] && [ "$ASSET_ID" != "null" ]; then
echo "Lösche altes Asset mit ID ${ASSET_ID}..." echo "Lösche altes Asset mit ID ${ASSET_ID}..."
curl -s -X DELETE \ curl -s -X DELETE \
-H "Authorization: token ${TOKEN}" \ -H "Authorization: token ${TOKEN}" \