diff --git a/packaging/env.sh b/packaging/env.sh index 616831e..b68406a 100644 --- a/packaging/env.sh +++ b/packaging/env.sh @@ -62,6 +62,17 @@ smoke_bin() { } # Emit a GitHub Actions warning (plain stderr outside Actions). +# Run a command up to five times, 15 s apart: for steps that ask a remote service (Apple's +# notarization ticket service drops connections now and then). +retry() { + local attempt + for attempt in 1 2 3 4 5; do + "$@" && return 0 + [ "$attempt" = 5 ] || { echo "retrying ($attempt/5): $*" >&2; sleep 15; } + done + return 1 +} + warn() { if [ -n "${GITHUB_ACTIONS:-}" ]; then echo "::warning::$*"; else echo "warning: $*" >&2; fi } diff --git a/packaging/macos/package.sh b/packaging/macos/package.sh index 8e693b8..87abe94 100755 --- a/packaging/macos/package.sh +++ b/packaging/macos/package.sh @@ -135,8 +135,8 @@ codesign --verify --strict --deep --verbose=2 "$APP" if [ "$NOTARIZE" = 1 ]; then ditto -c -k --keepParent "$APP" "$WORK/FigCraft-notarize.zip" notarize "$WORK/FigCraft-notarize.zip" - xcrun stapler staple "$APP" - xcrun stapler validate "$APP" + retry xcrun stapler staple "$APP" + retry xcrun stapler validate "$APP" spctl --assess --type execute -vvv "$APP" fi @@ -156,8 +156,8 @@ sign "$DMG" codesign --verify --strict --verbose=2 "$DMG" if [ "$NOTARIZE" = 1 ]; then notarize "$DMG" - xcrun stapler staple "$DMG" - xcrun stapler validate "$DMG" + retry xcrun stapler staple "$DMG" + retry xcrun stapler validate "$DMG" spctl --assess --type open --context context:primary-signature -vvv "$DMG" fi diff --git a/packaging/macos/verify.sh b/packaging/macos/verify.sh index 6c36c33..6080cf8 100755 --- a/packaging/macos/verify.sh +++ b/packaging/macos/verify.sh @@ -130,7 +130,7 @@ fi echo "==> $(basename "$DMG")" codesign --verify --strict --verbose=2 "$DMG" if [ "$STRICT" = 1 ]; then - xcrun stapler validate "$DMG" || fail "no notarization ticket stapled to the DMG" + retry xcrun stapler validate "$DMG" || fail "no notarization ticket stapled to the DMG" assess --assess --type open --context context:primary-signature -vv "$DMG" \ || fail "Gatekeeper rejects the DMG" fi