#!/bin/bash set -euo pipefail if [ "$#" -eq 1 ] && { [ "$1" = "--help" ] || [ "$1" = "-h" ]; }; then echo "Usage: $0 [output-directory]" exit 0 fi if [[ $# -lt 1 || $# -gt 2 ]]; then echo "Usage: $0 [output-directory]" >&2 exit 2 fi repo_root="$(cd "$(dirname "$0")/../.." && pwd)" runtime_root="$(cd "$1" && pwd)" output_root="${2:-$repo_root/dist/macos}" signing_identity="${CUTDEX_CODESIGN_IDENTITY:--}" python="${PYTHON:-python3}" flutter="${FLUTTER:-flutter}" app="$repo_root/build/macos/Build/Products/Release-production/cutdex.app" resources="$app/Contents/Resources" embedded_runtime="$resources/processing" mkdir -p "$output_root" output_root="$(cd "$output_root" && pwd)" archive="$output_root/cutdex-macos14-arm64.zip" dmg="$output_root/cutdex-macos14-arm64.dmg" if [[ -n "${CUTDEX_NOTARY_PROFILE:-}" && "$signing_identity" == "-" ]]; then echo "CUTDEX_NOTARY_PROFILE requires a Developer ID signing identity" >&2 exit 1 fi if [[ -n "${CUTDEX_UPDATE_FEED_URL:-}${CUTDEX_UPDATE_PUBLIC_KEY:-}" ]]; then if [[ -z "${CUTDEX_UPDATE_FEED_URL:-}" || -z "${CUTDEX_UPDATE_PUBLIC_KEY:-}" ]]; then echo "Set both CUTDEX_UPDATE_FEED_URL and CUTDEX_UPDATE_PUBLIC_KEY" >&2 exit 1 fi fi # Fail before the Flutter build if a worker or a transitive library is missing. "$python" "$repo_root/tool/macos/check_macos_release.py" --runtime "$runtime_root" cd "$repo_root" bash "$repo_root/tool/macos/check_macos_build_target.sh" "$app/Contents/MacOS/cutdex" rm -rf "$embedded_runtime" "$flutter" build macos --release --flavor production \ --split-debug-info=build/symbols/macos mkdir -p "$resources" "$output_root" ditto "$runtime_root" "$embedded_runtime" if [[ -n "${CUTDEX_UPDATE_FEED_URL:-}" ]]; then "$python" "$repo_root/tool/macos/macos_updates.py" configure --app "$app" \ --feed "$CUTDEX_UPDATE_FEED_URL" --public-key "$CUTDEX_UPDATE_PUBLIC_KEY" fi bash "$repo_root/tool/macos/sign_macos_app.sh" "$app" "$python" "$repo_root/tool/macos/check_macos_release.py" --app "$app" \ --report "$output_root/package-check.json" rm -f "$archive" ditto -c -k --sequesterRsrc --keepParent "$app" "$archive" if [[ -n "${CUTDEX_NOTARY_PROFILE:-}" ]]; then xcrun notarytool submit "$archive" \ --keychain-profile "$CUTDEX_NOTARY_PROFILE" --wait xcrun stapler staple "$app" rm -f "$archive" ditto -c -k --sequesterRsrc --keepParent "$app" "$archive" fi bash "$repo_root/tool/macos/create_macos_dmg.sh" "$app" "$dmg" if [[ -n "${CUTDEX_NOTARY_PROFILE:-}" ]]; then xcrun notarytool submit "$dmg" \ --keychain-profile "$CUTDEX_NOTARY_PROFILE" --wait xcrun stapler staple "$dmg" xcrun stapler validate "$dmg" fi echo "App: $app" echo "Archive: $archive" shasum -a 256 "$archive" echo "DMG: $dmg" shasum -a 256 "$dmg"