#!/bin/bash set +x set +v set -euo pipefail cd "$(dirname "$0")/.." # shellcheck source=Scripts/product.env source Scripts/product.env source Scripts/packaging-paths.sh value() { local name="${PRODUCT_ENV_PREFIX}_$1"; printf '%s' "${!name:-}"; } fail() { printf '%s\n' "$*" >&2; exit 1; } identity=$(value SIGN_IDENTITY) profile=$(value NOTARY_PROFILE) key=$(value NOTARY_KEY) key_id=$(value NOTARY_KEY_ID) issuer=$(value NOTARY_ISSUER) [[ -n $identity && $identity != - ]] || fail 'Set a Developer ID Application signing identity.' if [[ ${GITHUB_ACTIONS:-} == true ]]; then [[ ${RUNNER_ENVIRONMENT:-} == github-hosted ]] || fail 'Notarization requires a GitHub-hosted runner.' [[ -n $key && -n $key_id && -n $issuer ]] || fail 'CI notarization requires an App Store Connect API key.' fi if [[ -n $key ]]; then [[ -f $key && ! -L $key && -n $key_id && -n $issuer ]] || fail 'Provide a safe App Store Connect key, key ID, and issuer.' credentials=(--key "$key" --key-id "$key_id" --issuer "$issuer") else [[ -n $profile ]] || fail 'Set an App Store Connect notarytool profile or API key.' credentials=(--keychain-profile "$profile") fi app=$(value SIGNING_APP) app=$(packaging_app_path "${app:-build/$PRODUCT_NAME.app}") dmg=$(value DMG_PATH) dmg=${dmg:-build/$PRODUCT_NAME.dmg} [[ ! -e $dmg && ! -L $dmg ]] || fail "Refusing to overwrite: $dmg" dmg=$(packaging_output_path "$dmg") [[ -d $(dirname "$dmg") ]] || fail "Output directory not found: $(dirname "$dmg")" Scripts/bundle-preflight.sh "$app" codesign --verify --strict --deep "$app" lipo "$app/Contents/MacOS/$PRODUCT_NAME" -verify_arch arm64 x86_64 lipo "$app/Contents/Resources/bin/$PRODUCT_CLI" -verify_arch arm64 x86_64 work=$(mktemp -d "${TMPDIR:-/tmp}/$PRODUCT_CASK-notary.XXXXXX") trap 'rm -rf "$work"' EXIT # Notarization must see the same signature and contents that reach the installer. ditto "$app" "$work/$PRODUCT_NAME.app" xattr -cr "$work/$PRODUCT_NAME.app" ditto -c -k --sequesterRsrc --keepParent "$work/$PRODUCT_NAME.app" "$work/$PRODUCT_NAME.zip" submit() { local artifact=$1 if ! xcrun notarytool submit "$artifact" "${credentials[@]}" --wait --output-format json > "$work/receipt.json"; then printf 'Notarization failed for %s:\n' "$artifact" >&2 /bin/cat "$work/receipt.json" >&2 exit 1 fi if ! Scripts/parcel-dev.sh notary-accepted "$work/receipt.json"; then printf 'Notarization was not accepted for %s:\n' "$artifact" >&2 /bin/cat "$work/receipt.json" >&2 exit 1 fi } staple() { local artifact=$1 action for action in staple validate; do if ! xcrun stapler "$action" "$artifact" > "$work/stapler.log" 2>&1; then printf 'Could not %s %s:\n' "$action" "$artifact" >&2 /bin/cat "$work/stapler.log" >&2 return 1 fi done } submit "$work/$PRODUCT_NAME.zip" staple "$work/$PRODUCT_NAME.app" artifact="$work/$PRODUCT_NAME.dmg" Scripts/dmg.sh "$work/$PRODUCT_NAME.app" "$artifact" submit "$artifact" staple "$artifact" mv -n "$artifact" "$dmg" [[ ! -e $artifact ]] || fail "Refusing to overwrite: $dmg"