Skip to content

Commit 4b8a6db

Browse files
committed
turns out order was wrong
1 parent 9b77e1a commit 4b8a6db

1 file changed

Lines changed: 57 additions & 36 deletions

File tree

scripts/sign-macos.sh

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ APP_DIR="$RELEASE_DIR/macos"
66
APP_NAME="Rustcast.app"
77
APP_PATH="$APP_DIR/$APP_NAME"
88

9-
# --- Required env vars (using the names you provided) ---
9+
# --- Required env vars ---
1010
environment=(
1111
"MACOS_CERTIFICATE"
1212
"MACOS_CERTIFICATE_PWD"
1313
"MACOS_CI_KEYCHAIN_PWD"
1414
"MACOS_CERTIFICATE_NAME"
15-
"MACOS_NOTARIZATION_PWD"
1615
"MACOS_NOTARY_TEAM_ID"
1716
"MACOS_NOTARY_KEY_ID"
1817
"MACOS_NOTARY_KEY"
18+
"MACOS_NOTARY_ISSUER_ID"
1919
)
2020

2121
for var in "${environment[@]}"; do
@@ -25,71 +25,92 @@ for var in "${environment[@]}"; do
2525
fi
2626
done
2727

28-
# Optional: only needed if you still want to keep this around
29-
: "${MACOS_NOTARISATION_APPLE_ID:=}"
28+
# --- Step 1: Decode the notarization API key FIRST ---
29+
echo "Preparing notarization API key..."
30+
NOTARY_KEY_FILE="AuthKey.p8"
31+
if printf '%s' "$MACOS_NOTARY_KEY" | grep -q "BEGIN PRIVATE KEY"; then
32+
printf '%s' "$MACOS_NOTARY_KEY" > "$NOTARY_KEY_FILE"
33+
else
34+
printf '%s' "$MACOS_NOTARY_KEY" | base64 --decode > "$NOTARY_KEY_FILE"
35+
fi
3036

31-
echo "Decoding certificate"
37+
# --- Step 2: Decode and install the signing certificate ---
38+
echo "Decoding certificate..."
3239
echo "$MACOS_CERTIFICATE" | base64 --decode > certificate.p12
3340

34-
echo "Installing cert in a new keychain"
41+
echo "Installing cert in a new keychain..."
3542
security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain
3643
security default-keychain -s build.keychain
3744
security unlock-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain
3845
security import certificate.p12 -k build.keychain -P "$MACOS_CERTIFICATE_PWD" -T /usr/bin/codesign
3946
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_CI_KEYCHAIN_PWD" build.keychain
4047

41-
echo "Signing..."
42-
/usr/bin/codesign --force -s "$MACOS_CERTIFICATE_NAME" --options runtime --timestamp "$APP_PATH" -v
43-
48+
# --- Step 3: Sign the app ---
49+
echo "Signing app..."
50+
/usr/bin/codesign \
51+
--force \
52+
--deep \
53+
--options runtime \
54+
--timestamp \
55+
-s "$MACOS_CERTIFICATE_NAME" \
56+
-v \
57+
"$APP_PATH"
58+
59+
# --- Step 4: Verify the signature (not notarization yet) ---
60+
echo "Verifying signature..."
4461
/usr/bin/codesign --verify --deep --strict --verbose=2 "$APP_PATH"
45-
spctl --assess --type execute --verbose "$APP_PATH"
4662

47-
echo "Creating temp notarization archive"
63+
# --- Step 5: Create notarization zip ---
64+
echo "Creating notarization archive..."
4865
ditto -c -k --keepParent "$APP_PATH" "notarization.zip"
4966

67+
# --- Step 6: Submit for notarization ---
68+
echo "Submitting for notarization..."
5069
SUBMIT_JSON=$(xcrun notarytool submit "notarization.zip" \
5170
--key "$NOTARY_KEY_FILE" \
5271
--key-id "$MACOS_NOTARY_KEY_ID" \
5372
--issuer "$MACOS_NOTARY_ISSUER_ID" \
5473
--output-format json)
5574

5675
echo "$SUBMIT_JSON"
57-
5876
SUBMIT_ID=$(echo "$SUBMIT_JSON" | jq -r .id)
5977

60-
WAIT_STATUS=0
78+
if [[ -z "$SUBMIT_ID" || "$SUBMIT_ID" == "null" ]]; then
79+
echo "Error: Failed to get submission ID from notarytool"
80+
exit 1
81+
fi
82+
83+
echo "Submission ID: $SUBMIT_ID"
6184

85+
# --- Step 7: Wait for notarization to complete ---
86+
echo "Waiting for notarization result..."
87+
WAIT_STATUS=0
6288
xcrun notarytool wait "$SUBMIT_ID" \
63-
--key "$NOTARY_KEY_FILE" --key-id "$MACOS_NOTARY_KEY_ID" --issuer "$MACOS_NOTARY_ISSUER_ID" \
89+
--key "$NOTARY_KEY_FILE" \
90+
--key-id "$MACOS_NOTARY_KEY_ID" \
91+
--issuer "$MACOS_NOTARY_ISSUER_ID" \
6492
--timeout 30m || WAIT_STATUS=$?
93+
94+
# --- Step 8: Fetch and print the notarization log ---
95+
echo "Fetching notarization log..."
6596
xcrun notarytool log "$SUBMIT_ID" \
66-
--key "$NOTARY_KEY_FILE" --key-id "$MACOS_NOTARY_KEY_ID" --issuer "$MACOS_NOTARY_ISSUER_ID" \
97+
--key "$NOTARY_KEY_FILE" \
98+
--key-id "$MACOS_NOTARY_KEY_ID" \
99+
--issuer "$MACOS_NOTARY_ISSUER_ID" \
67100
notarization-log.json || true
68101
cat notarization-log.json || true
102+
69103
if [[ $WAIT_STATUS -ne 0 ]]; then
70-
echo "Notarization did not succeed (wait exit $WAIT_STATUS)"
104+
echo "Notarization did not succeed (wait exit code: $WAIT_STATUS)"
71105
exit $WAIT_STATUS
72106
fi
73107

74-
echo "Notarize app (API key auth)"
75-
# MACOS_NOTARY_KEY can be either:
76-
# - the *contents* of the .p8 key, or
77-
# - base64 of the .p8 key (recommended for CI)
78-
#
79-
# If it's base64, decode it first.
80-
NOTARY_KEY_FILE="AuthKey.p8"
81-
if printf '%s' "$MACOS_NOTARY_KEY" | grep -q "BEGIN PRIVATE KEY"; then
82-
printf '%s' "$MACOS_NOTARY_KEY" > "$NOTARY_KEY_FILE"
83-
else
84-
printf '%s' "$MACOS_NOTARY_KEY" | base64 --decode > "$NOTARY_KEY_FILE"
85-
fi
108+
# --- Step 9: Staple the notarization ticket ---
109+
echo "Stapling notarization ticket..."
110+
xcrun stapler staple "$APP_PATH"
86111

87-
# xcrun notarytool submit "notarization.zip" \
88-
# --team-id "$MACOS_NOTARY_TEAM_ID" \
89-
# --issuer "$MACOS_NOTARY_ISSUER_ID" \
90-
# --key-id "$MACOS_NOTARY_KEY_ID" \
91-
# --key "$NOTARY_KEY_FILE" \
92-
# --wait
112+
# --- Step 10: Final Gatekeeper check (AFTER stapling) ---
113+
echo "Running Gatekeeper assessment..."
114+
spctl --assess --type execute --verbose "$APP_PATH"
93115

94-
echo "Attach staple"
95-
xcrun stapler staple "$APP_PATH"
116+
echo "Done! App is signed, notarized, and stapled."

0 commit comments

Comments
 (0)