Skip to content

Commit 1fa53c4

Browse files
committed
chore: add scripts/release-macos.sh for one-shot signed DMG release builds
Builds + signs + verifies both Apple Silicon and Intel DMGs; detaches stale volumes; signs the Intel app in place inside the DMG (keeps the drag-to-Applications layout); optional --publish cuts the GitHub release with notes from CHANGELOG.
1 parent 99872c3 commit 1fa53c4

2 files changed

Lines changed: 171 additions & 0 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,25 @@ Run `pnpm install` before any build command. `pnpm tauri build` runs the
201201
frontend build (`tsc -b && vite build`) automatically. Release artifacts are
202202
generated by Tauri under `target/**/release/bundle/`.
203203

204+
### One-shot macOS release build (recommended)
205+
206+
For a full release, use the release script — it builds **both** the Apple
207+
Silicon and Intel signed DMGs and verifies them:
208+
209+
```bash
210+
scripts/release-macos.sh # build + sign + verify both DMGs
211+
scripts/release-macos.sh --publish # also create the GitHub release for v<version>
212+
```
213+
214+
It handles the manual footguns: detaching a stale `/Volumes/FlowClone` before
215+
each build (it otherwise collides with `bundle_dmg.sh`), and ad-hoc signing the
216+
**Intel** app — which, when cross-compiled on Apple Silicon, is *not* signed by
217+
default and would trip Gatekeeper's "app is damaged" on Intel Macs. The Intel
218+
app is signed in place inside Tauri's DMG so the drag-to-Applications layout is
219+
preserved. `--publish` reads the release notes from `CHANGELOG.md` and needs an
220+
authenticated `gh`. The manual per-target steps below still work if you need one
221+
specific artifact.
222+
204223
**Bundle the CLI sidecar first.** Image Migration and Restore run the
205224
`flowclone` CLI for the privileged raw I/O, bundled into the app as a Tauri
206225
sidecar. Build it for the **same target** you pass to `tauri build`, otherwise

scripts/release-macos.sh

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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

Comments
 (0)