fix: make release upload idempotent, delete existing assets before re-upload
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5e8828e4ee
commit
ae32883cef
|
|
@ -156,12 +156,12 @@ jobs:
|
|||
TOKEN="${{ secrets.GITHUB_TOKEN }}"
|
||||
VER="${GITHUB_REF_NAME#v}"
|
||||
|
||||
# Create release, fall back to existing if already present
|
||||
# Create release or get existing
|
||||
RELEASE=$(curl -s -X POST "${API}/repos/${REPO}/releases" \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\"}")
|
||||
RELEASE_ID=$(echo "${RELEASE}" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])" 2>/dev/null)
|
||||
RELEASE_ID=$(echo "${RELEASE}" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || true)
|
||||
if [ -z "${RELEASE_ID}" ]; then
|
||||
RELEASE=$(curl -s "${API}/repos/${REPO}/releases/tags/${TAG}" \
|
||||
-H "Authorization: token ${TOKEN}")
|
||||
|
|
@ -169,11 +169,27 @@ jobs:
|
|||
fi
|
||||
echo "Release ID: ${RELEASE_ID}"
|
||||
|
||||
# Upload assets
|
||||
# Upload assets (delete existing with same name first)
|
||||
for file in \
|
||||
"artifacts/build-net9/Jellyfin-AutoBackup-${VER}-10.11.x.zip" \
|
||||
"artifacts/build-net10/Jellyfin-AutoBackup-${VER}-12.0.x.zip"; do
|
||||
NAME=$(basename "${file}")
|
||||
|
||||
# Delete existing asset if present
|
||||
ASSETS=$(curl -s "${API}/repos/${REPO}/releases/${RELEASE_ID}/assets" \
|
||||
-H "Authorization: token ${TOKEN}")
|
||||
ASSET_ID=$(echo "${ASSETS}" | python3 -c "
|
||||
import sys,json
|
||||
assets=json.load(sys.stdin)
|
||||
a=next((x for x in assets if x['name']=='${NAME}'),None)
|
||||
print(a['id'] if a else '')
|
||||
" 2>/dev/null || true)
|
||||
if [ -n "${ASSET_ID}" ]; then
|
||||
echo "Deleting existing asset ${NAME} (id=${ASSET_ID})..."
|
||||
curl -s -X DELETE "${API}/repos/${REPO}/releases/${RELEASE_ID}/assets/${ASSET_ID}" \
|
||||
-H "Authorization: token ${TOKEN}"
|
||||
fi
|
||||
|
||||
echo "Uploading ${NAME}..."
|
||||
HTTP_CODE=$(curl -s -o /tmp/upload_response.json -w "%{http_code}" \
|
||||
-X POST "${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${NAME}" \
|
||||
|
|
|
|||
Loading…
Reference in New Issue