diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 68adfa1..8a46419 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -508,8 +508,17 @@ jobs: echo "lookup: ${existing:-}" >&2 exit 1 fi + # Re-running a release replaces its assets: delete the old ones by name first. + existing_assets="$(curl -sS -H "Authorization: token ${TOKEN}" \ + "${api}/releases/${release_id}/assets" || true)" for file in dist/*; do name="$(basename "${file}")" + asset_id="$(printf '%s' "${existing_assets}" | python3 -c 'import json,sys; name=sys.argv[1]; print(next((a.get("id","") for a in json.load(sys.stdin) if a.get("name")==name), ""))' "${name}" 2>/dev/null || true)" + if [ -n "${asset_id}" ]; then + curl -fsS -X DELETE -H "Authorization: token ${TOKEN}" \ + "${api}/releases/assets/${asset_id}" >/dev/null + echo "replaced ${name}" + fi curl -fsS -X POST -H "Authorization: token ${TOKEN}" \ -F "attachment=@${file}" "${api}/releases/${release_id}/assets?name=${name}" >/dev/null echo "uploaded ${name}"