#!/bin/bash set -euo pipefail cd "$(dirname "$0")/.." if [[ -n "${NOTARY_PROFILE:-}" && -z "${SIGN_IDENTITY:-}" ]]; then echo "Notarization requires SIGN_IDENTITY." >&2 exit 2 fi source Scripts/build-paths.sh destination="${1:-$base/dist}" ./Scripts/build.sh Release --no-launch stage="$(mktemp -d "$base/release.XXXXXXXX")" trap 'rm -rf -- "$stage"' EXIT app="$stage/AIStudio.app" ditto "$derived/Build/Products/Release/AIStudio.app" "$app" if [[ "$(xcrun lipo -archs "$app/Contents/MacOS/AIStudio")" != "arm64" ]]; then echo "Expected an arm64-only release executable." >&2 exit 1 fi version="$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "$app/Contents/Info.plist")" if [[ -n "${SIGN_IDENTITY:-}" ]]; then # The hardened app and its embedded framework must share a signing team. codesign --force --timestamp --options runtime --sign "$SIGN_IDENTITY" "$app/Contents/Frameworks/llama.framework" codesign --force --timestamp --options runtime --sign "$SIGN_IDENTITY" "$app" else codesign --force --sign - "$app" fi codesign --verify --deep --strict "$app" archive="AIStudio-$version-macOS-arm64.zip" if [[ -n "${NOTARY_PROFILE:-}" ]]; then ditto -c -k --keepParent "$app" "$stage/notarization.zip" xcrun notarytool submit "$stage/notarization.zip" --keychain-profile "$NOTARY_PROFILE" --wait xcrun stapler staple "$app" xcrun stapler validate "$app" fi ditto -c -k --keepParent "$app" "$stage/$archive" mkdir -p "$destination" mv "$stage/$archive" "$destination/$archive" (cd "$destination" && shasum -a 256 "$archive" > "$archive.sha256") printf 'Release: %s\n' "$destination/$archive"