#!/bin/sh # Build a universal (Apple silicon + Intel) package of one workflow from a # clean checkout of , so local configuration (prefs.plist) and # uncommitted work can't ship. # # scripts/package [rev] -> dist/robust-alfred-.alfredworkflow set -eu name=$1 rev=${2:-HEAD} root=$(cd "$(dirname "$0")/.." && pwd) bin=robust-alfred-$name out=$root/dist/$bin.alfredworkflow work=$(mktemp -d) trap 'git -C "$root" worktree remove --force "$work/src" 2>/dev/null; trash "$work"' EXIT git -C "$root" worktree add --quiet --detach "$work/src" "$rev" # Reuse the repo's build cache; only the sources come from the checkout. export CARGO_TARGET_DIR="$root/target" for target in aarch64-apple-darwin x86_64-apple-darwin; do cargo build --quiet --release --locked \ --manifest-path "$work/src/Cargo.toml" -p "$bin" --target "$target" done pkg=$work/pkg cp -R "$work/src/workflows/$name/workflow" "$pkg" lipo -create -output "$pkg/$bin" \ "$CARGO_TARGET_DIR/aarch64-apple-darwin/release/$bin" \ "$CARGO_TARGET_DIR/x86_64-apple-darwin/release/$bin" if [ -e "$pkg/prefs.plist" ]; then echo "error: prefs.plist would be packaged" >&2 exit 1 fi # Hotkeys ship unbound: a key combination is the user's to choose, and the # repo's plist carries whatever the developer bound while it was linked. plist=$pkg/info.plist count=$(plutil -extract objects raw "$plist") i=0 while [ "$i" -lt "$count" ]; do if [ "$(plutil -extract "objects.$i.type" raw "$plist")" = alfred.workflow.trigger.hotkey ]; then for key in hotkey hotmod hotstring; do plutil -remove "objects.$i.config.$key" "$plist" 2>/dev/null || true done fi i=$((i + 1)) done archs=$(lipo -archs "$pkg/$bin") case "$archs" in *arm64*x86_64* | *x86_64*arm64*) ;; *) echo "error: binary has architectures '$archs', expected arm64 and x86_64" >&2 exit 1 ;; esac mkdir -p "$root/dist" [ ! -e "$out" ] || trash "$out" (cd "$pkg" && zip -qrX "$out" .) echo "$out"