From 93f6aaea76e4316956c9109d8d0d50b5b6daaec9 Mon Sep 17 00:00:00 2001 From: datadunia Date: Sat, 9 May 2026 01:57:11 +0700 Subject: [PATCH] feat: check and delete existing release before creating a new one --- .gitea/workflows/deploy_call.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.gitea/workflows/deploy_call.yaml b/.gitea/workflows/deploy_call.yaml index 8be4bf0..4096ccb 100644 --- a/.gitea/workflows/deploy_call.yaml +++ b/.gitea/workflows/deploy_call.yaml @@ -79,6 +79,21 @@ jobs: TAG="${{ gitea.ref_name }}" API="${{ gitea.server_url }}/api/v1" + # 0. Check & Delete Existing Release + echo "=== 0. Check & Delete Existing Release ===" + EXISTING_RESP=$(curl -s -H "Authorization: token $TOKEN" "$API/repos/$REPO/releases/tags/$TAG") + EXISTING_ID=$(echo "$EXISTING_RESP" | grep -o '"id":[0-9]*' | head -n 1 | cut -d':' -f2 || true) + + if [ -n "$EXISTING_ID" ] && [ "$EXISTING_ID" != "null" ]; then + echo "⚠️ Found existing release for tag $TAG with ID: $EXISTING_ID. Deleting..." + DELETE_RESP=$(curl -s -w "\n%{http_code}" -X DELETE -H "Authorization: token $TOKEN" "$API/repos/$REPO/releases/$EXISTING_ID") + echo "✅ Delete response: $DELETE_RESP" + else + echo "No existing release found for $TAG. Proceeding..." + fi + + # 1. Create Release + echo "=== 1. Create New Release ===" JSON_BODY=$(printf '{"tag_name":"%s","name":"%s","body":"Release %s","draft":false,"prerelease":%s}' "$TAG" "$TAG" "$TAG" "${{ inputs.prerelease }}") RELEASE_RESP=$(curl -s -X POST \