@@ -339,21 +339,40 @@ jobs:
339339 with :
340340 subject-path : dist/*.tar.gz
341341
342- # Draft first, publish last: users never see a release with some of its
343- # assets missing. A re-run finishes an existing draft but never touches
344- # a release that was already published.
342+ # Draft first, publish last: a release this job creates never shows up
343+ # with some of its assets missing. A release published by hand from the
344+ # GitHub UI (which is what pushed the tag) gets its assets added instead.
345+ # Re-runs are safe: published assets are never replaced, only checked.
345346 - name : Publish release
346347 run : |
347348 if draft="$(gh release view "$TAG" --json isDraft --jq .isDraft 2>/dev/null)"; then
348- if [[ "$draft" != true ]]; then
349- echo "::error::release $TAG is already published; bump the version instead"
350- exit 1
351- fi
349+ echo "release $TAG exists (draft: $draft)"
352350 else
353351 flags=()
354352 [[ "$PRERELEASE" == true ]] && flags+=(--prerelease)
355353 gh release create "$TAG" --draft --verify-tag --generate-notes \
356354 --title "remmy $VERSION" "${flags[@]}"
355+ draft=true
356+ fi
357+
358+ if [[ "$draft" == true ]]; then
359+ gh release upload "$TAG" dist/* --clobber
360+ gh release edit "$TAG" --draft=false
361+ exit 0
357362 fi
358- gh release upload "$TAG" dist/* --clobber
359- gh release edit "$TAG" --draft=false
363+
364+ published="$(gh release view "$TAG" --json assets \
365+ --jq '.assets[] | "\(.name) \(.digest)"')"
366+ for file in dist/*; do
367+ name="$(basename "$file")"
368+ want="sha256:$(sha256sum "$file" | cut -d' ' -f1)"
369+ have="$(awk -v n="$name" '$1 == n {print $2}' <<< "$published")"
370+ if [[ -z "$have" ]]; then
371+ gh release upload "$TAG" "$file"
372+ elif [[ "$have" != "$want" ]]; then
373+ echo "::error::$name on published release $TAG differs from this build; not replacing it"
374+ exit 1
375+ else
376+ echo "$name already published and identical"
377+ fi
378+ done
0 commit comments