Explorar o código

fix: rebuild checksums.txt from release asset digests when it is missing

gh release upload --clobber deletes the old asset first, so a run whose
manifest uploads all fail can leave the release with no checksums.txt,
and a re-run then failed at the download. Rebuild it from the sha256
digests GitHub records for each release asset instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jamesread hai 22 horas
pai
achega
dc91535a24
Modificáronse 2 ficheiros con 32 adicións e 4 borrados
  1. 1 1
      docs/modules/dev/pages/signing.adoc
  2. 31 3
      var/release/publish-signed-assets.sh

+ 1 - 1
docs/modules/dev/pages/signing.adoc

@@ -17,7 +17,7 @@ Like Windows signing, this happens **after** the release is published, so a prob
 
 If `sign-macos` fails (for example an expired Apple agreement, a notary outage or a certificate problem), the release stays published without macOS assets. Fix the cause, then use **Re-run failed jobs** on that workflow run. The unsigned artifact must still be within its retention period.
 
-The signed files are uploaded before `checksums.txt`. If the `checksums.txt` upload still fails after retries, the job fails and the release holds the new files with an out-of-date manifest. A re-run recomputes the manifest from the release's current `checksums.txt` and uploads it again.
+The signed files are uploaded before `checksums.txt`. If the `checksums.txt` upload still fails after retries, the job fails and the release holds the new files with an out-of-date manifest. A re-run updates the release's current `checksums.txt` and uploads it again. If the failed upload left the release with no `checksums.txt`, the re-run rebuilds it from the sha256 digests GitHub records for each release asset.
 
 `sign-windows` and `sign-macos` share a concurrency group, so they never update `checksums.txt` at the same time.
 

+ 31 - 3
var/release/publish-signed-assets.sh

@@ -43,9 +43,37 @@ for src in "$@"; do
 done
 
 checksums_path="${DIST_DIR}/${CHECKSUMS_NAME}"
-if ! gh release download "${TAG}" --pattern "${CHECKSUMS_NAME}" --dir "${DIST_DIR}" --clobber; then
-  echo "Failed to download ${CHECKSUMS_NAME} from release ${TAG}" >&2
-  exit 1
+
+# gh release upload --clobber deletes the old asset before uploading, so an
+# earlier run that failed to upload the manifest can leave the release without
+# one. The manifest lists every other release asset, so it can be rebuilt from
+# the sha256 digests GitHub records for them.
+rebuild_checksums() {
+  echo "${CHECKSUMS_NAME} is missing from release ${TAG}; rebuilding it from release asset digests" >&2
+  local assets
+  assets="$(gh release view "${TAG}" --json assets \
+    --jq ".assets[] | select(.name != \"${CHECKSUMS_NAME}\") | \"\(.digest // \"none\") \(.name)\"")"
+
+  : > "${checksums_path}"
+  local digest name
+  while read -r digest name; do
+    [[ -n "${name}" ]] || continue
+    if [[ "${digest}" != sha256:* ]]; then
+      echo "Release asset ${name} has no sha256 digest; cannot rebuild ${CHECKSUMS_NAME}" >&2
+      exit 1
+    fi
+    printf '%s  %s\n' "${digest#sha256:}" "${name}" >> "${checksums_path}"
+  done <<< "${assets}"
+}
+
+release_assets="$(gh release view "${TAG}" --json assets --jq '.assets[].name')"
+if grep -qxF "${CHECKSUMS_NAME}" <<< "${release_assets}"; then
+  if ! gh release download "${TAG}" --pattern "${CHECKSUMS_NAME}" --dir "${DIST_DIR}" --clobber; then
+    echo "Failed to download ${CHECKSUMS_NAME} from release ${TAG}" >&2
+    exit 1
+  fi
+else
+  rebuild_checksums
 fi
 if [[ ! -f "${checksums_path}" ]]; then
   echo "${CHECKSUMS_NAME} not found after download from release ${TAG}" >&2