Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

macOS packaging: retry stapler when Apple's CloudKit drops the connection

Brandon Thomas2ea0dfc11f4d
diff --git a/packaging/macos/package.sh b/packaging/macos/package.sh
index c68ded7b5..8b8f6c41e 100755
--- a/packaging/macos/package.sh
+++ b/packaging/macos/package.sh
@@ -80,6 +80,21 @@ sign() {
codesign --force --sign "$IDENTITY" ${kc[@]+"${kc[@]}"} "${ts[@]}" "$@"
}
+# `stapler staple` and `stapler validate` both fetch the ticket from Apple's CloudKit, and a dropped
+# connection there (NSURLErrorDomain -1005, "Error 68") fails them although notarization worked.
+# Both are idempotent, so retry with a pause; a missing or bad ticket still fails every try.
+stapler_retry() {
+ local try
+ for try in 1 2 3 4; do
+ xcrun stapler "$1" "$2" && return 0
+ [[ "$try" = 4 ]] && break
+ echo "stapler $1 failed (try $try of 4); retrying in $((try * 20)) s" >&2
+ sleep $((try * 20))
+ done
+ echo "error: stapler $1 $(basename "$2") failed 4 times" >&2
+ exit 1
+}
+
notarize() {
local file="$1" out id status
echo "==> notarizing $(basename "$file") (this can take a few minutes)"
@@ -122,8 +137,8 @@ codesign --verify --strict --deep --verbose=2 "$APP"
if [[ "$NOTARIZE" = 1 ]]; then
ditto -c -k --keepParent "$APP" "$WORK/DesignCraft-notarize.zip"
notarize "$WORK/DesignCraft-notarize.zip"
- xcrun stapler staple "$APP"
- xcrun stapler validate "$APP"
+ stapler_retry staple "$APP"
+ stapler_retry validate "$APP"
spctl --assess --type execute -vvv "$APP"
fi
@@ -173,8 +188,8 @@ fi
hdiutil_retry detach detach "$MOUNT" >/dev/null
if [[ "$NOTARIZE" = 1 ]]; then
notarize "$DMG"
- xcrun stapler staple "$DMG"
- xcrun stapler validate "$DMG"
+ stapler_retry staple "$DMG"
+ stapler_retry validate "$DMG"
spctl --assess --type open --context context:primary-signature -vvv "$DMG"
fi