From 2462bdf0979e35feba75ccc5e8a6e6f3fcdbc321 Mon Sep 17 00:00:00 2001 From: Mateusz Stomski Date: Fri, 9 Oct 2026 20:28:09 +0200 Subject: [PATCH] fix(ci): make release asset step resilient against set -e in Gitea Actions --- .gitea/workflows/release.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index cf5f01e..b438aff 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -97,7 +97,7 @@ jobs: echo "[INFO] Ensuring Gitea Release exists for tag ${TAG_NAME}..." REL_INFO=$(curl -k -s -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}/releases/tags/${TAG_NAME}") - REL_ID=$(echo "$REL_INFO" | grep -o '"id":[0-9]*' | head -n 1 | cut -d: -f2) + REL_ID=$(python3 -c "import sys, json; data=json.loads(sys.argv[1]); print(data.get('id', ''))" "$REL_INFO" 2>/dev/null || true) if [[ -z "$REL_ID" || "$REL_ID" == "null" ]]; then echo "[INFO] Creating release for tag ${TAG_NAME}..." @@ -109,13 +109,13 @@ jobs: "draft": false, "prerelease": false } - EOF - ) +EOF +) NEW_REL=$(curl -k -s -X POST -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ -d "$CREATE_PAYLOAD" \ "${API_URL}/releases") - REL_ID=$(echo "$NEW_REL" | grep -o '"id":[0-9]*' | head -n 1 | cut -d: -f2) + REL_ID=$(python3 -c "import sys, json; data=json.loads(sys.argv[1]); print(data.get('id', ''))" "$NEW_REL" 2>/dev/null || true) fi echo "[INFO] Release ID: ${REL_ID}" @@ -127,11 +127,11 @@ jobs: echo "[INFO] Uploading asset: ${FNAME}..." # Delete existing asset with same name if present - EXISTING_ASSETS=$(curl -k -s -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}/releases/${REL_ID}/assets") - ASSET_ID=$(echo "$EXISTING_ASSETS" | grep -B 2 "\"name\":\"${FNAME}\"" | grep -o '"id":[0-9]*' | head -n 1 | cut -d: -f2 || true) + EXISTING_ASSETS=$(curl -k -s -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}/releases/${REL_ID}/assets" || echo "[]") + ASSET_ID=$(python3 -c "import sys, json; assets=json.loads(sys.argv[1]) if sys.argv[1] else []; fname=sys.argv[2]; print(next((str(a['id']) for a in assets if isinstance(a, dict) and a.get('name') == fname), ''))" "$EXISTING_ASSETS" "$FNAME" 2>/dev/null || true) if [[ -n "$ASSET_ID" ]]; then echo "[INFO] Deleting existing asset ${FNAME} (ID: ${ASSET_ID})..." - curl -k -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}/releases/${REL_ID}/assets/${ASSET_ID}" + curl -k -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${API_URL}/releases/${REL_ID}/assets/${ASSET_ID}" || true fi # Upload asset