Refactor: Verwendung von jq zur präziseren ID-Extraktion aus JSON-Responses mit Fallback auf grep
This commit is contained in:
@@ -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}" \
|
||||
|
||||
@@ -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}" \
|
||||
|
||||
Reference in New Issue
Block a user