diff --git a/packaging/macos/import-cert.sh b/packaging/macos/import-cert.sh index de16f22d43..c07f524864 100755 --- a/packaging/macos/import-cert.sh +++ b/packaging/macos/import-cert.sh @@ -24,9 +24,19 @@ KEYCHAIN="$TMP/pdfcraft-signing.keychain-db" CERT="$TMP/pdfcraft-signing.p12" KC_PASS="${KEYCHAIN_PASSWORD:-$(openssl rand -hex 24)}" -# Every exit path removes the keychain and the folder holding it: the keychain keeps the signing -# identity, and each run makes a new folder under a temporary parent that can outlive the job. -trap 'rm -f "$CERT"; security delete-keychain "$KEYCHAIN" 2>/dev/null || true; rm -rf "$TMP"' EXIT +# The decoded bundle is removed on every exit. The keychain and its folder are kept on success, +# because package.sh signs with them in a later step (the release workflow's clean-up step deletes +# the keychain), and removed only when this script fails. +cleanup() { + local status=$? + rm -f "$CERT" + if [[ "$status" -ne 0 ]]; then + security delete-keychain "$KEYCHAIN" 2>/dev/null || true + rm -rf "$TMP" + fi + exit "$status" +} +trap cleanup EXIT printf '%s' "$APPLE_CERTIFICATE" | base64 --decode >"$CERT" security create-keychain -p "$KC_PASS" "$KEYCHAIN" security set-keychain-settings -lut 21600 "$KEYCHAIN"