ci(release): upsert release and replace matching assets
All checks were successful
Push Validation / validate (push) Successful in 52s

This commit is contained in:
Micheal Wilkinson
2026-03-20 18:42:53 +00:00
parent 71e411e12d
commit 8fadb8299c
2 changed files with 30 additions and 11 deletions

View File

@@ -128,16 +128,17 @@ 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
fi
else
curl --fail-with-body \
-X POST \
-H "Authorization: token ${RELEASE_TOKEN}" \
@@ -145,6 +146,7 @@ jobs:
"${release_api}" \
--data "{\"tag_name\":\"${tag}\",\"target\":\"${GITHUB_SHA}\",\"name\":\"${tag}\",\"body\":\"${escaped_release_notes}\",\"draft\":false,\"prerelease\":false}" \
--output release.json
fi
release_id="$(sed -n 's/.*"id"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' release.json | head -n 1)"
if [[ -z "$release_id" ]]; then
@@ -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}" \

View File

@@ -64,7 +64,7 @@ The `Prepare Release` workflow creates a release and uploads prebuilt `vociferat
- `windows/arm64`
It also uploads `checksums.txt` for integrity verification.
If a release already exists for the same tag, the workflow replaces it so release notes and attached binaries stay in sync.
If a release already exists for the same tag, the workflow updates its release notes and replaces matching asset filenames so reruns stay in sync.
## Reuse In Other Repositories