ci(release): replace existing release assets on republish
Re-running the pipeline for an already published tag would otherwise fail with a 409 on every asset name. Delete the matching asset first.
This commit is contained in:
1 parent
ff562acc1a
commit
6618de7d94
1 file changed
+9
@@ -508,8 +508,17 @@ jobs:
|
|||||||
echo "lookup: ${existing:-<none>}" >&2
|
echo "lookup: ${existing:-<none>}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
for file in dist/*; do
|
||||||
name="$(basename "${file}")"
|
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}" \
|
curl -fsS -X POST -H "Authorization: token ${TOKEN}" \
|
||||||
-F "attachment=@${file}" "${api}/releases/${release_id}/assets?name=${name}" >/dev/null
|
-F "attachment=@${file}" "${api}/releases/${release_id}/assets?name=${name}" >/dev/null
|
||||||
echo "uploaded ${name}"
|
echo "uploaded ${name}"
|
||||||
|
|||||||
Reference in new issue
Block a user