|
1 | | -#!/usr/bin/env -S bash -e |
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
2 | 3 |
|
3 | | -ENTITLEMENTS_PATH="assets/entitlements.plist" |
| 4 | +RELEASE_DIR="target/release" |
| 5 | +APP_DIR="$RELEASE_DIR/macos" |
| 6 | +APP_NAME="Rustcast.app" |
| 7 | +APP_PATH="$APP_DIR/$APP_NAME" |
4 | 8 |
|
5 | | -APP_BUNDLE_PATH="${APP_BUNDLE_PATH:?APP_BUNDLE_PATH not set}" |
| 9 | +# --- Required env vars (using the names you provided) --- |
| 10 | +environment=( |
| 11 | + "MACOS_CERTIFICATE" |
| 12 | + "MACOS_CERTIFICATE_PWD" |
| 13 | + "MACOS_CI_KEYCHAIN_PWD" |
| 14 | + "MACOS_CERTIFICATE_NAME" |
| 15 | + "MACOS_NOTARIZATION_PWD" |
| 16 | + "MACOS_NOTARY_TEAM_ID" |
| 17 | + "MACOS_NOTARY_KEY_ID" |
| 18 | + "MACOS_NOTARY_KEY" |
| 19 | +) |
6 | 20 |
|
7 | | -# 1. Create a temporary keychain and import certificate |
8 | | -KEYCHAIN=build.keychain-db |
| 21 | +for var in "${environment[@]}"; do |
| 22 | + if [[ -z "${!var:-}" ]]; then |
| 23 | + echo "Error: $var is not set" |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | +done |
9 | 27 |
|
10 | | -if security list-keychains | grep -q "$KEYCHAIN"; then |
11 | | - echo "Keychain $KEYCHAIN already exists, using existing keychain." |
| 28 | +# Optional: only needed if you still want to keep this around |
| 29 | +: "${MACOS_NOTARISATION_APPLE_ID:=}" |
| 30 | + |
| 31 | +echo "Decoding certificate" |
| 32 | +echo "$MACOS_CERTIFICATE" | base64 --decode > certificate.p12 |
| 33 | + |
| 34 | +echo "Installing cert in a new keychain" |
| 35 | +security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain |
| 36 | +security default-keychain -s build.keychain |
| 37 | +security unlock-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain |
| 38 | +security import certificate.p12 -k build.keychain -P "$MACOS_CERTIFICATE_PWD" -T /usr/bin/codesign |
| 39 | +security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_CI_KEYCHAIN_PWD" build.keychain |
| 40 | + |
| 41 | +echo "Signing..." |
| 42 | +/usr/bin/codesign --force -s "$MACOS_CERTIFICATE_NAME" --options runtime --timestamp "$APP_PATH" -v |
| 43 | + |
| 44 | +/usr/bin/codesign --verify --deep --strict --verbose=2 "$APP_PATH" |
| 45 | +spctl --assess --type execute --verbose "$APP_PATH" |
| 46 | + |
| 47 | +echo "Creating temp notarization archive" |
| 48 | +ditto -c -k --keepParent "$APP_PATH" "notarization.zip" |
| 49 | + |
| 50 | +SUBMIT_JSON=$(xcrun notarytool submit "notarization.zip" \ |
| 51 | + --key "$NOTARY_KEY_FILE" \ |
| 52 | + --key-id "$MACOS_NOTARY_KEY_ID" \ |
| 53 | + --issuer "$MACOS_NOTARY_ISSUER_ID" \ |
| 54 | + --output-format json) |
| 55 | + |
| 56 | +echo "$SUBMIT_JSON" |
| 57 | + |
| 58 | +SUBMIT_ID=$(echo "$SUBMIT_JSON" | jq -r .id) |
| 59 | + |
| 60 | +WAIT_STATUS=0 |
| 61 | + |
| 62 | +xcrun notarytool wait "$SUBMIT_ID" \ |
| 63 | + --key "$NOTARY_KEY_FILE" --key-id "$MACOS_NOTARY_KEY_ID" --issuer "$MACOS_NOTARY_ISSUER_ID" \ |
| 64 | + --timeout 30m || WAIT_STATUS=$? |
| 65 | +xcrun notarytool log "$SUBMIT_ID" \ |
| 66 | + --key "$NOTARY_KEY_FILE" --key-id "$MACOS_NOTARY_KEY_ID" --issuer "$MACOS_NOTARY_ISSUER_ID" \ |
| 67 | + notarization-log.json || true |
| 68 | +cat notarization-log.json || true |
| 69 | +if [[ $WAIT_STATUS -ne 0 ]]; then |
| 70 | + echo "Notarization did not succeed (wait exit $WAIT_STATUS)" |
| 71 | + exit $WAIT_STATUS |
| 72 | +fi |
| 73 | + |
| 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" |
12 | 83 | else |
13 | | - security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" "$KEYCHAIN" |
| 84 | + printf '%s' "$MACOS_NOTARY_KEY" | base64 --decode > "$NOTARY_KEY_FILE" |
14 | 85 | fi |
15 | 86 |
|
16 | | -security default-keychain -s "$KEYCHAIN" |
17 | | -security unlock-keychain -p "$MACOS_CI_KEYCHAIN_PWD" "$KEYCHAIN" |
18 | | -security set-keychain-settings "$KEYCHAIN" |
19 | | -security default-keychain -s "$KEYCHAIN" |
20 | | -security unlock-keychain -p "$MACOS_CI_KEYCHAIN_PWD" "$KEYCHAIN" |
21 | | -security set-keychain-settings "$KEYCHAIN" |
| 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 |
22 | 93 |
|
23 | | -echo "$MACOS_CERTIFICATE" | base64 --decode > certificate.p12 |
24 | | -security import certificate.p12 \ |
25 | | - -k "$KEYCHAIN" \ |
26 | | - -P "$MACOS_CERTIFICATE_PWD" \ |
27 | | - -T /usr/bin/codesign |
28 | | - |
29 | | -security set-key-partition-list -S apple-tool:,apple:,codesign: \ |
30 | | - -s -k "$MACOS_CI_KEYCHAIN_PWD" "$KEYCHAIN" |
31 | | - |
32 | | -# 2. Sign app bundle |
33 | | -codesign --deep --force --options runtime --timestamp \ |
34 | | - --entitlements $ENTITLEMENTS_PATH \ |
35 | | - --sign "$MACOS_CERTIFICATE_NAME" \ |
36 | | - "$APP_BUNDLE_PATH" |
37 | | - |
38 | | -codesign --verify --deep --strict --verbose=2 "$APP_BUNDLE_PATH" |
39 | | -echo "Signed app at $APP_BUNDLE_PATH" |
| 94 | +echo "Attach staple" |
| 95 | +xcrun stapler staple "$APP_PATH" |
0 commit comments