|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Build signed macOS DMGs (Apple Silicon + Intel) for a FlowClone release, and |
| 4 | +# optionally publish them as the GitHub Release for the current version's tag. |
| 5 | +# |
| 6 | +# This scripts the recurring, error-prone manual steps: |
| 7 | +# - A stale `/Volumes/FlowClone` left mounted from a previous build collides |
| 8 | +# with tauri's `bundle_dmg.sh` and fails the next DMG build — so we detach it |
| 9 | +# before each build. |
| 10 | +# - x86_64 apps cross-compiled on Apple Silicon are NOT code-signed (the arm64 |
| 11 | +# native build is auto ad-hoc signed by the linker; the cross build is not). |
| 12 | +# An unsigned app inside a DMG triggers Gatekeeper's "app is damaged" on |
| 13 | +# Intel Macs — so we ad-hoc sign the x86_64 app. |
| 14 | +# - Re-bundling the x86_64 DMG from scratch (`hdiutil create`) loses tauri's |
| 15 | +# layout (the drag-to-Applications alias). Instead we sign the app *in place* |
| 16 | +# inside tauri's own DMG (convert to read-write, mount, sign, convert back), |
| 17 | +# keeping the layout AND the signature. |
| 18 | +# - Every DMG is verified (the app inside is actually signed) before we trust it. |
| 19 | +# |
| 20 | +# Usage: |
| 21 | +# scripts/release-macos.sh # build + sign + verify both DMGs |
| 22 | +# scripts/release-macos.sh --publish # also create the GitHub release for v<version> |
| 23 | +# |
| 24 | +# NEVER run as root. Requires: pnpm, rustup (targets auto-added), the built-in |
| 25 | +# codesign, and — for --publish — an authenticated `gh` CLI. Ad-hoc signing is |
| 26 | +# not a substitute for Apple Developer ID + notarization; users still right-click |
| 27 | +# → Open on first launch. |
| 28 | +set -euo pipefail |
| 29 | +cd "$(dirname "$0")/.." |
| 30 | + |
| 31 | +VOLUME="FlowClone" |
| 32 | +ARM_TRIPLE="aarch64-apple-darwin" |
| 33 | +INTEL_TRIPLE="x86_64-apple-darwin" |
| 34 | +PUBLISH=false |
| 35 | +[ "${1:-}" = "--publish" ] && PUBLISH=true |
| 36 | + |
| 37 | +if [ "$(id -u)" = "0" ]; then |
| 38 | + echo "error: do not run the release build as root" >&2 |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +VERSION=$(node -p "require('./apps/desktop/src-tauri/tauri.conf.json').version") |
| 43 | +echo "==> FlowClone release build for v$VERSION" |
| 44 | + |
| 45 | +ARM_DMG="target/$ARM_TRIPLE/release/bundle/dmg/FlowClone_${VERSION}_aarch64.dmg" |
| 46 | +INTEL_DMG="target/$INTEL_TRIPLE/release/bundle/dmg/FlowClone_${VERSION}_x64.dmg" |
| 47 | + |
| 48 | +# Detach any leftover mount of our volume (exact name, plus Finder's " 1"/" 2" |
| 49 | +# duplicates) so bundle_dmg.sh can create a fresh one. |
| 50 | +detach_stale_volume() { |
| 51 | + for vol in "/Volumes/$VOLUME" "/Volumes/$VOLUME 1" "/Volumes/$VOLUME 2"; do |
| 52 | + [ -d "$vol" ] && hdiutil detach "$vol" -force >/dev/null 2>&1 || true |
| 53 | + done |
| 54 | +} |
| 55 | + |
| 56 | +# Fail unless the app inside $1 (a .dmg) is code-signed. |
| 57 | +verify_dmg_signed() { |
| 58 | + local dmg="$1" |
| 59 | + detach_stale_volume |
| 60 | + hdiutil attach "$dmg" -nobrowse -readonly >/dev/null 2>&1 |
| 61 | + local sig |
| 62 | + sig=$(codesign -dv "/Volumes/$VOLUME/FlowClone.app" 2>&1 | grep -E "^Signature=" || true) |
| 63 | + hdiutil detach "/Volumes/$VOLUME" >/dev/null 2>&1 || true |
| 64 | + if [ -z "$sig" ]; then |
| 65 | + echo " !! app inside $(basename "$dmg") is NOT signed" >&2 |
| 66 | + return 1 |
| 67 | + fi |
| 68 | + echo " verified: $(basename "$dmg") — app $sig" |
| 69 | +} |
| 70 | + |
| 71 | +# Ad-hoc sign the app inside $1 (a .dmg) in place, preserving tauri's layout. |
| 72 | +# Converts the read-only DMG to read-write, mounts it, signs the app, then |
| 73 | +# converts back to a compressed read-only DMG, replacing the original. |
| 74 | +sign_dmg_app_in_place() { |
| 75 | + local dmg="$1" |
| 76 | + local tmp |
| 77 | + tmp=$(mktemp -d) |
| 78 | + detach_stale_volume |
| 79 | + hdiutil convert "$dmg" -format UDRW -o "$tmp/rw.dmg" >/dev/null |
| 80 | + hdiutil attach "$tmp/rw.dmg" -nobrowse >/dev/null |
| 81 | + codesign --force --deep -s - "/Volumes/$VOLUME/FlowClone.app" |
| 82 | + hdiutil detach "/Volumes/$VOLUME" >/dev/null |
| 83 | + hdiutil convert "$tmp/rw.dmg" -format UDZO -o "$tmp/final.dmg" >/dev/null |
| 84 | + mv -f "$tmp/final.dmg" "$dmg" |
| 85 | + rm -rf "$tmp" |
| 86 | +} |
| 87 | + |
| 88 | +echo "==> building CLI sidecars (both arches)" |
| 89 | +bash scripts/build-sidecar.sh "$ARM_TRIPLE" "$INTEL_TRIPLE" |
| 90 | + |
| 91 | +echo "==> building Apple Silicon DMG ($ARM_TRIPLE)" |
| 92 | +detach_stale_volume |
| 93 | +pnpm tauri build --target "$ARM_TRIPLE" --bundles app,dmg |
| 94 | +# The arm64 app is ad-hoc signed by the linker; just confirm it. |
| 95 | +verify_dmg_signed "$ARM_DMG" |
| 96 | + |
| 97 | +echo "==> building Intel DMG ($INTEL_TRIPLE)" |
| 98 | +detach_stale_volume |
| 99 | +pnpm tauri build --target "$INTEL_TRIPLE" --bundles app,dmg |
| 100 | +# The cross-compiled app is unsigned — sign it in place inside tauri's DMG. |
| 101 | +echo " signing the Intel app inside the DMG (keeps the drag-to-Applications layout)" |
| 102 | +sign_dmg_app_in_place "$INTEL_DMG" |
| 103 | +verify_dmg_signed "$INTEL_DMG" |
| 104 | + |
| 105 | +echo "" |
| 106 | +echo "==> DMGs ready:" |
| 107 | +echo " $ARM_DMG" |
| 108 | +echo " $INTEL_DMG" |
| 109 | + |
| 110 | +if [ "$PUBLISH" = false ]; then |
| 111 | + echo "" |
| 112 | + echo "To publish this release, run:" |
| 113 | + echo " scripts/release-macos.sh --publish" |
| 114 | + echo "or manually:" |
| 115 | + echo " gh release create v$VERSION \\" |
| 116 | + echo " \"$ARM_DMG\" \\" |
| 117 | + echo " \"$INTEL_DMG\" --title \"FlowClone $VERSION\" --notes-file <notes>" |
| 118 | + exit 0 |
| 119 | +fi |
| 120 | + |
| 121 | +echo "" |
| 122 | +echo "==> publishing GitHub release v$VERSION" |
| 123 | +if ! git rev-parse "v$VERSION" >/dev/null 2>&1; then |
| 124 | + echo "error: tag v$VERSION does not exist — create and push it first" >&2 |
| 125 | + exit 1 |
| 126 | +fi |
| 127 | + |
| 128 | +# Pull the release notes from this version's CHANGELOG section, if present. |
| 129 | +NOTES_FILE=$(mktemp) |
| 130 | +awk -v ver="## [$VERSION]" ' |
| 131 | + index($0, ver) == 1 { grab = 1; next } |
| 132 | + grab && /^## \[/ { exit } |
| 133 | + grab { print } |
| 134 | +' CHANGELOG.md > "$NOTES_FILE" |
| 135 | +if [ ! -s "$NOTES_FILE" ]; then |
| 136 | + printf '## FlowClone %s\n\nSee CHANGELOG.md for details.\n' "$VERSION" > "$NOTES_FILE" |
| 137 | +fi |
| 138 | +# Append the download key so users pick the right build. |
| 139 | +{ |
| 140 | + echo "" |
| 141 | + echo "**Download:**" |
| 142 | + echo "- \`$(basename "$ARM_DMG")\` — Apple Silicon (M1/M2/M3/M4)" |
| 143 | + echo "- \`$(basename "$INTEL_DMG")\` — Intel Macs" |
| 144 | +} >> "$NOTES_FILE" |
| 145 | + |
| 146 | +gh release create "v$VERSION" \ |
| 147 | + "$ARM_DMG" \ |
| 148 | + "$INTEL_DMG" \ |
| 149 | + --title "FlowClone $VERSION" \ |
| 150 | + --notes-file "$NOTES_FILE" |
| 151 | +rm -f "$NOTES_FILE" |
| 152 | +echo "==> published: $(gh release view "v$VERSION" --json url --jq .url)" |
0 commit comments