From 589d0f6be125bb2e40350fb49daeac4bd94bac01 Mon Sep 17 00:00:00 2001 From: DragonSlayer_14 Date: Sun, 23 Aug 2026 13:09:27 +0200 Subject: [PATCH] =?UTF-8?q?Refactor:=20Verwendung=20von=20jq=20zur=20pr?= =?UTF-8?q?=C3=A4ziseren=20ID-Extraktion=20aus=20JSON-Responses=20mit=20Fa?= =?UTF-8?q?llback=20auf=20grep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/dev.yml | 8 ++++---- .gitea/workflows/main.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/dev.yml b/.gitea/workflows/dev.yml index c30e352..769a0df 100644 --- a/.gitea/workflows/dev.yml +++ b/.gitea/workflows/dev.yml @@ -97,7 +97,7 @@ jobs: RELEASE_ID="" 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})." else echo "Erstelle neues Preview-Release ${TAG_NAME}..." @@ -117,7 +117,7 @@ jobs: -H "Content-Type: application/json" \ -d "$CREATE_PAYLOAD" \ "${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})." fi @@ -135,8 +135,8 @@ jobs: filename="$(basename "$file")" 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) - if [ -n "$ASSET_ID" ]; then + 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" ] && [ "$ASSET_ID" != "null" ]; then echo "Lösche altes Asset mit ID ${ASSET_ID}..." curl -s -X DELETE \ -H "Authorization: token ${TOKEN}" \ diff --git a/.gitea/workflows/main.yml b/.gitea/workflows/main.yml index 2043dea..9f24c2d 100644 --- a/.gitea/workflows/main.yml +++ b/.gitea/workflows/main.yml @@ -97,7 +97,7 @@ jobs: RELEASE_ID="" 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})." else echo "Erstelle neues Release ${TAG_NAME}..." @@ -117,7 +117,7 @@ jobs: -H "Content-Type: application/json" \ -d "$CREATE_PAYLOAD" \ "${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})." fi @@ -135,8 +135,8 @@ jobs: filename="$(basename "$file")" 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) - if [ -n "$ASSET_ID" ]; then + 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" ] && [ "$ASSET_ID" != "null" ]; then echo "Lösche altes Asset mit ID ${ASSET_ID}..." curl -s -X DELETE \ -H "Authorization: token ${TOKEN}" \