Просмотр исходного кода

fix: rebuild an incomplete checksums.txt and document the no-digest recovery (#1203)

James Read 21 часов назад
Родитель
Сommit
4d804ae826
2 измененных файлов с 35 добавлено и 5 удалено
  1. 29 1
      docs/modules/dev/pages/signing.adoc
  2. 6 4
      var/release/publish-signed-assets.sh

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

@@ -17,7 +17,35 @@ 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.
 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 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.
+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`, or with one GitHub has not marked as fully uploaded, the re-run rebuilds it from the sha256 digests GitHub records for each release asset.
+
+A re-run trusts a fully uploaded `checksums.txt`. It only adds or replaces lines for the files it signs, so it cannot restore entries for other assets that are missing from it.
+
+Rebuild the manifest by hand from the release's own files when a fully uploaded `checksums.txt` is missing entries for other assets, or when a release asset has no recorded digest (the rebuild then stops and the re-run fails). Then re-run the job.
+
+Before you start, make sure no `sign-windows` or `sign-macos` job is running or queued for the release. The manual commands are outside the jobs' concurrency group, so a job that updates `checksums.txt` while they run would have its lines overwritten.
+
+The commands run in a subshell that stops at the first error, so a failed download or hash never uploads a partial manifest. They also stop if any asset other than `checksums.txt` is not fully uploaded, because hashing a partial file would publish a checksum for the wrong bytes. Upload that asset again, or delete it with `gh release delete-asset`, then run the commands again. A signed file deleted here is uploaded again when you re-run the job that signed it: `sign-windows` for Windows files, `sign-macos` for macOS files.
+
+[source,bash]
+----
+(
+  set -euo pipefail
+  tag=<tag>
+  incomplete="$(gh release view "${tag}" --repo OliveTin/OliveTin --json assets \
+    --jq '.assets[] | select(.name != "checksums.txt" and .state != "uploaded") | .name')"
+  if [[ -n "${incomplete}" ]]; then
+    echo "Not fully uploaded: ${incomplete}" >&2
+    exit 1
+  fi
+  workdir="$(mktemp -d)"
+  mkdir "${workdir}/assets"
+  gh release download "${tag}" --repo OliveTin/OliveTin --dir "${workdir}/assets"
+  rm -f "${workdir}/assets/checksums.txt"
+  (cd "${workdir}/assets" && sha256sum -- *) > "${workdir}/checksums.txt"
+  gh release upload "${tag}" "${workdir}/checksums.txt" --repo OliveTin/OliveTin --clobber
+)
+----
 
 
 `sign-windows` and `sign-macos` share a concurrency group, so they never update `checksums.txt` at the same time.
 `sign-windows` and `sign-macos` share a concurrency group, so they never update `checksums.txt` at the same time.
 
 

+ 6 - 4
var/release/publish-signed-assets.sh

@@ -46,10 +46,10 @@ checksums_path="${DIST_DIR}/${CHECKSUMS_NAME}"
 
 
 # gh release upload --clobber deletes the old asset before uploading, so an
 # 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
 # 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
+# one, or with an incomplete one. The manifest lists every other release asset, so it can be rebuilt from
 # the sha256 digests GitHub records for them.
 # the sha256 digests GitHub records for them.
 rebuild_checksums() {
 rebuild_checksums() {
-  echo "${CHECKSUMS_NAME} is missing from release ${TAG}; rebuilding it from release asset digests" >&2
+  echo "${CHECKSUMS_NAME} is missing or incomplete on release ${TAG}; rebuilding it from release asset digests" >&2
   local assets
   local assets
   assets="$(gh release view "${TAG}" --json assets \
   assets="$(gh release view "${TAG}" --json assets \
     --jq ".assets[] | select(.name != \"${CHECKSUMS_NAME}\") | \"\(.digest // \"none\") \(.name)\"")"
     --jq ".assets[] | select(.name != \"${CHECKSUMS_NAME}\") | \"\(.digest // \"none\") \(.name)\"")"
@@ -66,8 +66,10 @@ rebuild_checksums() {
   done <<< "${assets}"
   done <<< "${assets}"
 }
 }
 
 
-release_assets="$(gh release view "${TAG}" --json assets --jq '.assets[].name')"
-if grep -qxF "${CHECKSUMS_NAME}" <<< "${release_assets}"; then
+# A failed upload can leave an empty asset in the "starter" state; only an
+# "uploaded" manifest is complete enough to update.
+uploaded_assets="$(gh release view "${TAG}" --json assets --jq '.assets[] | select(.state == "uploaded") | .name')"
+if grep -qxF "${CHECKSUMS_NAME}" <<< "${uploaded_assets}"; then
   if ! gh release download "${TAG}" --pattern "${CHECKSUMS_NAME}" --dir "${DIST_DIR}" --clobber; then
   if ! gh release download "${TAG}" --pattern "${CHECKSUMS_NAME}" --dir "${DIST_DIR}" --clobber; then
     echo "Failed to download ${CHECKSUMS_NAME} from release ${TAG}" >&2
     echo "Failed to download ${CHECKSUMS_NAME} from release ${TAG}" >&2
     exit 1
     exit 1