ci(release): upsert release and replace matching assets
All checks were successful
Push Validation / validate (push) Successful in 52s
All checks were successful
Push Validation / validate (push) Successful in 52s
This commit is contained in:
@@ -128,24 +128,26 @@ jobs:
|
||||
fi
|
||||
|
||||
curl --fail-with-body \
|
||||
-X DELETE \
|
||||
-X PATCH \
|
||||
-H "Authorization: token ${RELEASE_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${release_api}/${existing_release_id}"
|
||||
"${release_api}/${existing_release_id}" \
|
||||
--data "{\"tag_name\":\"${tag}\",\"target\":\"${GITHUB_SHA}\",\"name\":\"${tag}\",\"body\":\"${escaped_release_notes}\",\"draft\":false,\"prerelease\":false}" \
|
||||
--output release.json
|
||||
elif [[ "$status_code" != "404" ]]; then
|
||||
echo "Unexpected response while checking release ${tag}: HTTP ${status_code}" >&2
|
||||
cat release-existing.json >&2
|
||||
exit 1
|
||||
else
|
||||
curl --fail-with-body \
|
||||
-X POST \
|
||||
-H "Authorization: token ${RELEASE_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${release_api}" \
|
||||
--data "{\"tag_name\":\"${tag}\",\"target\":\"${GITHUB_SHA}\",\"name\":\"${tag}\",\"body\":\"${escaped_release_notes}\",\"draft\":false,\"prerelease\":false}" \
|
||||
--output release.json
|
||||
fi
|
||||
|
||||
curl --fail-with-body \
|
||||
-X POST \
|
||||
-H "Authorization: token ${RELEASE_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${release_api}" \
|
||||
--data "{\"tag_name\":\"${tag}\",\"target\":\"${GITHUB_SHA}\",\"name\":\"${tag}\",\"body\":\"${escaped_release_notes}\",\"draft\":false,\"prerelease\":false}" \
|
||||
--output release.json
|
||||
|
||||
release_id="$(sed -n 's/.*"id"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' release.json | head -n 1)"
|
||||
if [[ -z "$release_id" ]]; then
|
||||
echo "Failed to parse release id from API response" >&2
|
||||
@@ -194,6 +196,23 @@ jobs:
|
||||
|
||||
for asset in dist/*; do
|
||||
name="$(basename "$asset")"
|
||||
|
||||
assets_json="$(curl -sS --fail-with-body \
|
||||
-H "Authorization: token ${RELEASE_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${release_api}")"
|
||||
|
||||
escaped_name="$(printf '%s' "$name" | sed 's/[][(){}.^$*+?|\\/]/\\&/g')"
|
||||
existing_asset_id="$(printf '%s' "$assets_json" | tr -d '\n' | sed -n "s/.*{\"id\":\([0-9][0-9]*\)[^}]*\"name\":\"${escaped_name}\".*/\1/p")"
|
||||
|
||||
if [[ -n "$existing_asset_id" ]]; then
|
||||
curl --fail-with-body \
|
||||
-X DELETE \
|
||||
-H "Authorization: token ${RELEASE_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
"${release_api}/${existing_asset_id}"
|
||||
fi
|
||||
|
||||
curl --fail-with-body \
|
||||
-X POST \
|
||||
-H "Authorization: token ${RELEASE_TOKEN}" \
|
||||
|
||||
Reference in New Issue
Block a user