bundle_app.sh

2.5 KB · raw

1#!/bin/bash2# Bundle Haven into a signed .app and zip it for distribution.3#4# Driven by koh offer --builds via kepr.build, which sets KEPR_PLATFORM5# per-platform. macos-aarch64 builds natively; macos-x86_64 cross-compiles6# from Apple Silicon via Swift's --triple flag.7#8# Output: Haven.app.zip in the repo root, ready for koh to upload as the9# release artifact for this platform.10set -euo pipefail1112APP_NAME="Haven"13BUNDLE="${APP_NAME}.app"14ZIP="${APP_NAME}.app.zip"15ENTITLEMENTS="${APP_NAME}.entitlements"1617# Wipe stale outputs so re-runs are idempotent and we never ship a18# half-codesigned bundle left over from a previous attempt.19rm -rf "${BUNDLE}" "${ZIP}"2021# Build the executable in release mode. Package.swift declares the product22# as `Haven` (capital H); .build/release is a symlink to23# <arch>-apple-macosx/release so this path works for both native and24# cross-compiled builds.25case "${KEPR_PLATFORM:-}" in26    macos-x86_64)27        echo "  → swift build -c release --triple x86_64-apple-macosx"28        swift build -c release --triple x86_64-apple-macosx29        ;;30    macos-aarch64|"")31        echo "  → swift build -c release"32        swift build -c release33        ;;34    *)35        echo "  → swift build -c release (unknown KEPR_PLATFORM='${KEPR_PLATFORM}', defaulting to native)"36        swift build -c release37        ;;38esac3940# Verify the binary actually materialised where we expect it. Catching this41# here beats waiting for koh's "output binary not found" message at the42# upload step.43if [ ! -f ".build/release/${APP_NAME}" ]; then44    echo "✗ .build/release/${APP_NAME} not produced" >&245    exit 146fi4748# Assemble the bundle. The directory shape is what Finder + codesign expect:49# Contents/MacOS/<executable>, Contents/Info.plist, Contents/Resources/.50mkdir -p "${BUNDLE}/Contents/MacOS"51mkdir -p "${BUNDLE}/Contents/Resources"52cp ".build/release/${APP_NAME}" "${BUNDLE}/Contents/MacOS/"53cp Info.plist "${BUNDLE}/Contents/"54if [ -f AppIcon.icns ]; then55    cp AppIcon.icns "${BUNDLE}/Contents/Resources/"56fi5758# Ad-hoc sign with the project's entitlements. Some macOS APIs require even59# an ad-hoc signature to recognise the bundle as runnable.60codesign --force --deep --entitlements "${ENTITLEMENTS}" --sign - "${BUNDLE}"6162# Zip with ditto — the canonical Apple tool. It preserves resource forks63# and extended attributes, which plain `zip` would mangle, and --keepParent64# stores Haven.app/ at the top of the archive so unzip reproduces the65# standard layout.66ditto -c -k --sequesterRsrc --keepParent "${BUNDLE}" "${ZIP}"6768echo "${ZIP} is ready."