Skip to content

Commit fdad302

Browse files
sheehanmunimclaude
andcommitted
fix(scripts): notarize and staple every Mac release
Releases were Developer ID signed but never notarized (notarization only ran when APPLE_API_* env vars happened to be set), so a DMG downloaded from GitHub or munimtech.com opened with "Apple could not verify MT Code is free of malware". The codesign step now notarizes + staples the app (so the updater ZIP carries its ticket) and then the DMG, using the `mtcode-notary` notarytool keychain profile by default, prints the notary log and fails the release on rejection, and verifies both with spctl. T3_SKIP_NOTARIZE=1 opts out for local test builds. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent cc8d5ab commit fdad302

1 file changed

Lines changed: 54 additions & 19 deletions

File tree

‎scripts/personal-codesign-mac-dmg.sh‎

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
#!/usr/bin/env bash
2-
# Developer ID codesign the .app inside a Munim Mac DMG, then rebuild DMG + ZIP.
3-
# Notarization requires an App Store Connect API Issuer ID (UUID) — set
4-
# APPLE_API_ISSUER (+ APPLE_API_KEY / APPLE_API_KEY_ID) to also submit + staple.
2+
# Developer ID codesign the .app inside a Munim Mac DMG, notarize + staple the
3+
# app and the DMG, then rebuild DMG + ZIP.
4+
#
5+
# Notarization is required: an unnotarized Developer ID build is what makes
6+
# macOS say "Apple could not verify MT Code is free of malware". Credentials
7+
# come from APPLE_API_ISSUER + APPLE_API_KEY_ID + APPLE_API_KEY when set, else
8+
# the notarytool keychain profile T3_NOTARY_PROFILE (default "mtcode-notary",
9+
# created with `xcrun notarytool store-credentials`). T3_SKIP_NOTARIZE=1 opts
10+
# out for local test builds only.
511
set -euo pipefail
612

713
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
@@ -74,6 +80,47 @@ NODE
7480

7581
codesign --verify --deep --strict "$APP"
7682

83+
NOTARY_ARGS=()
84+
if [[ -n "${APPLE_API_ISSUER:-}" && -n "${APPLE_API_KEY_ID:-}" && -n "${APPLE_API_KEY:-}" ]]; then
85+
KEY_FILE="$WORK/AuthKey.p8"
86+
if [[ -f "${APPLE_API_KEY}" ]]; then
87+
KEY_FILE="$APPLE_API_KEY"
88+
else
89+
printf '%s' "$APPLE_API_KEY" >"$KEY_FILE"
90+
fi
91+
NOTARY_ARGS=(--key "$KEY_FILE" --key-id "$APPLE_API_KEY_ID" --issuer "$APPLE_API_ISSUER")
92+
elif [[ "${T3_SKIP_NOTARIZE:-0}" != "1" ]]; then
93+
NOTARY_ARGS=(--keychain-profile "${T3_NOTARY_PROFILE:-mtcode-notary}")
94+
fi
95+
96+
notarize() {
97+
local target="$1" out
98+
echo "notarizing $(basename "$target")..."
99+
out="$(xcrun notarytool submit "$target" "${NOTARY_ARGS[@]}" --wait 2>&1)" || true
100+
printf '%s\n' "$out"
101+
if ! printf '%s\n' "$out" | grep -q "status: Accepted"; then
102+
local id
103+
id="$(printf '%s\n' "$out" | awk '/^ id: /{print $2; exit}')"
104+
if [[ -n "$id" ]]; then
105+
xcrun notarytool log "$id" "${NOTARY_ARGS[@]}" >&2 || true
106+
fi
107+
echo "notarization failed for $target" >&2
108+
exit 1
109+
fi
110+
}
111+
112+
if [[ ${#NOTARY_ARGS[@]} -gt 0 ]]; then
113+
# Staple the app itself so the updater ZIP carries its own ticket, then the
114+
# DMG built from it.
115+
APP_ZIP="$WORK/notarize-app.zip"
116+
ditto -c -k --sequesterRsrc --keepParent "$APP" "$APP_ZIP"
117+
notarize "$APP_ZIP"
118+
xcrun stapler staple "$APP"
119+
rm -f "$APP_ZIP"
120+
else
121+
echo "WARNING: T3_SKIP_NOTARIZE=1 -- this build will trip Gatekeeper on other Macs" >&2
122+
fi
123+
77124
STAGE="$WORK/stage"
78125
mkdir -p "$STAGE"
79126
ditto "$WORK/MT Code.app" "$STAGE/MT Code.app"
@@ -87,24 +134,12 @@ codesign --force --sign "$IDENTITY" --timestamp "$SIGNED_DMG"
87134
SIGNED_ZIP="$WORK/signed.zip"
88135
ditto -c -k --sequesterRsrc --keepParent "$WORK/MT Code.app" "$SIGNED_ZIP"
89136

90-
# Optional notarization when ASC API issuer is available.
91-
if [[ -n "${APPLE_API_ISSUER:-}" && -n "${APPLE_API_KEY_ID:-}" && -n "${APPLE_API_KEY:-}" ]]; then
92-
KEY_FILE="$WORK/AuthKey.p8"
93-
if [[ -f "${APPLE_API_KEY}" ]]; then
94-
KEY_FILE="$APPLE_API_KEY"
95-
else
96-
printf '%s' "$APPLE_API_KEY" >"$KEY_FILE"
97-
fi
98-
echo "submitting for notarization..."
99-
xcrun notarytool submit "$SIGNED_DMG" \
100-
--key "$KEY_FILE" \
101-
--key-id "$APPLE_API_KEY_ID" \
102-
--issuer "$APPLE_API_ISSUER" \
103-
--wait
137+
if [[ ${#NOTARY_ARGS[@]} -gt 0 ]]; then
138+
notarize "$SIGNED_DMG"
104139
xcrun stapler staple "$SIGNED_DMG"
140+
spctl -a -t open --context context:primary-signature -vv "$SIGNED_DMG"
141+
spctl -a -t exec -vv "$APP"
105142
echo "notarized + stapled"
106-
else
107-
echo "skipping notarization (set APPLE_API_ISSUER, APPLE_API_KEY_ID, APPLE_API_KEY to enable)"
108143
fi
109144

110145
cp "$SIGNED_DMG" "$DMG"

0 commit comments

Comments
 (0)