oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1#!/bin/zsh
2# A Calls Mac release, up to but not including publication: "Oficina Calls.app"
3# as works.oficina.calls, Developer ID signed inside out, notarised, stapled,
4# checked by Gatekeeper as a quarantined download, launched, and validated
5# against the feed by the publisher's own read-only plan.
6#
7# native/scripts/release-mac.sh <version> <build>
8# native/scripts/release-mac.sh 0.5.0 31
9#
10# It publishes nothing: no tag, no release asset, no appcast commit. The last
11# thing it prints is the publish command, for whoever publishes (see "Releasing
12# the Mac app" in native/README.md).
13#
14# Everything Calls-specific is read from the repository, not written here: the
15# bundle ID, feed and Sparkle key from native/mac-updates.json, the app's file
16# name from what scripts/bundle-mac.py built, and rastrillo/native's release
17# tools from the revision Package.resolved pins (apple/.build/checkouts/native).
18# So it cannot drift from the app the way release-calls-0.4.16.sh (outside the
19# repository, net.amadan.oficina.calls and build/Calls.app hard-coded) did.
20#
21# Environment:
22# IDENTITY Developer ID identity (default Team Tito Limited's)
23# TEAM its Team ID (default 9U4A84C4WK)
24# NOTARY_PROFILE notarytool keychain profile (default slopbox-notary)
25# RECORD release directory (default
26# ~/amadan.net/oficina/sparkle-worktrees/releases/calls-<version>-<build>);
27# it must not exist, unless it holds this build's finished
28# release, which is then checked and reused
29# ARTIFACTS the oficina/native-releases clone the plan is checked
30# against (default ~/amadan.net/oficina/sparkle-worktrees/native-releases);
31# unset or missing skips the plan with a warning
32# OFICINA_SKIP_PREPARE=1 reuse native/build's CallsBridge, RNNoise and
33# DeepFilter instead of rebuilding them (build-mac.sh)
34# ALLOW_DIRTY=1 build from a tree with local changes (a rehearsal only:
35# the release records the commit, which then does not name it)
36
37set -e -u -o pipefail
38setopt no_nomatch
39
40VERSION=${1:?usage: release-mac.sh <version> <build>}
41BUILD=${2:?usage: release-mac.sh <version> <build>}
42[[ $VERSION =~ '^[0-9]+(\.[0-9]+){0,2}$' ]] || { print -u2 "version must be numeric, like 0.5.0"; exit 2 }
43[[ $BUILD =~ '^[1-9][0-9]*$' ]] || { print -u2 "build must be a positive integer"; exit 2 }
44
45IDENTITY=${IDENTITY:-'Developer ID Application: Team Tito Limited (9U4A84C4WK)'}
46TEAM=${TEAM:-9U4A84C4WK}
47NOTARY_PROFILE=${NOTARY_PROFILE:-slopbox-notary}
48
49NATIVE=${0:A:h:h}
50REPO=${NATIVE:h}
51CONFIG=$NATIVE/mac-updates.json
52TOOLS=$NATIVE/apple/.build/checkouts/native/tools
53SPARKLE_BIN=$NATIVE/apple/.build/artifacts/sparkle/Sparkle/bin
54RECORD=${RECORD:-$HOME/amadan.net/oficina/sparkle-worktrees/releases/calls-$VERSION-$BUILD}
55ARTIFACTS=${ARTIFACTS-$HOME/amadan.net/oficina/sparkle-worktrees/native-releases}
56
57json() { python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))[sys.argv[2]])' "$@" }
58BUNDLE_ID=$(json "$CONFIG" bundle_id)
59FEED_URL=$(json "$CONFIG" feed_url)
60ZIP=$BUNDLE_ID-$BUILD.zip
61
62typeset -a NOTES
63STEP=0
64SMOKE_PID=""
65TMP=$(mktemp -d "${TMPDIR:-/tmp}/calls-release.XXXXXX")
66step() { STEP=$((STEP + 1)); print -P "\n%B%F{cyan}==> [$STEP/6] $*%f%b" }
67say() { print -r -- " $*" }
68ok() { print -n -P " %F{green}ok%f "; print -r -- "$*" }
69warn() { print -n -P " %F{yellow}warning:%f "; print -r -- "$*"; NOTES+=("$*") }
70die() { print -n -P "%F{red}error:%f " >&2; print -r -- "$*" >&2; exit 1 }
71need() { [[ -e $1 ]] || die "missing: $1" }
72plist() { plutil -extract "$2" raw -o - "$1/Contents/Info.plist" }
73on_exit() {
74 local rc=$?
75 [[ -n $SMOKE_PID ]] && kill "$SMOKE_PID" 2>/dev/null || true
76 rm -rf "$TMP"
77 (( rc == 0 )) || print -P "\n%F{red}%BFAILED%b at step $STEP, exit $rc. Nothing was published.%f" >&2
78}
79trap on_exit EXIT
80trap 'exit 130' INT TERM
81
82COMMIT=$(git -C "$REPO" rev-parse HEAD)
83print -P "%BOficina Calls $VERSION ($BUILD), $BUNDLE_ID%b, commit ${COMMIT[1,12]}"
84
85# ---- 1. Preflight (read-only) ---------------------------------------------
86step "Preflight: tree, tools, feed"
87if [[ -n $(git -C "$REPO" status --porcelain --untracked-files=no) ]]; then
88 [[ ${ALLOW_DIRTY:-0} == 1 ]] || die "the tree has local changes; commit them (or ALLOW_DIRTY=1 for a rehearsal)"
89 warn "built from a tree with local changes: $COMMIT does not name this build"
90fi
91[[ $BUNDLE_ID == works.oficina.calls ]] || die "mac-updates.json says $BUNDLE_ID, not works.oficina.calls"
92for tool in python3 curl shasum ditto xcrun spctl codesign; do command -v $tool >/dev/null || die "$tool not on PATH"; done
93# The pinned tools exist only after SwiftPM has resolved the package once.
94[[ -d $TOOLS ]] || swift package --package-path "$NATIVE/apple" resolve
95for file in "$TOOLS/release_mac.py" "$TOOLS/publish_mac_update.py" "$SPARKLE_BIN/sign_update" "$SPARKLE_BIN/generate_keys" "$SPARKLE_BIN/generate_appcast"; do need "$file"; done
96pinned=$(python3 -c 'import json,sys; print(next(p["state"]["revision"] for p in json.load(open(sys.argv[1]))["pins"] if p["identity"] == "native"))' "$NATIVE/apple/Package.resolved")
97checkout=$(git -C "$TOOLS/.." rev-parse HEAD)
98[[ $checkout == $pinned ]] || die "rastrillo/native checkout is ${checkout[1,7]}, Package.resolved pins ${pinned[1,7]}; run swift package resolve"
99ok "rastrillo/native tools at the pin, ${pinned[1,7]}"
100# The publisher refuses a build at or below any published one; say so now,
101# before twenty minutes of building and notarising.
102curl -fsS "$FEED_URL" -o "$TMP/feed.xml" || die "could not fetch $FEED_URL"
103newest=$(python3 - "$TMP/feed.xml" <<'PY'
104import sys, xml.etree.ElementTree as ET
105S = '{http://www.andymatuschak.org/xml-namespaces/sparkle}'
106print(max([int(v.text) for v in ET.parse(sys.argv[1]).iter(S + 'version')] or [0]))
107PY
108)
109(( BUILD > newest )) || die "the feed already has build $newest; this build must be above it"
110ok "feed's newest build is $newest; $BUILD is above it"
111
112# ---- 2. Keychain (read-only) ------------------------------------------------
113step "Keychain: Developer ID, Sparkle key, notary profile"
114[[ $(security find-identity -v -p codesigning) == *"\"$IDENTITY\""* ]] || die "no valid '$IDENTITY' identity"
115ok "$IDENTITY"
116key=$("$SPARKLE_BIN/generate_keys" --account "$(json "$CONFIG" keychain_account)" -p)
117[[ $key == $(json "$CONFIG" public_ed_key) ]] || die "the Sparkle key in the keychain is not mac-updates.json's public_ed_key"
118ok "Sparkle EdDSA key matches mac-updates.json"
119xcrun notarytool history --keychain-profile "$NOTARY_PROFILE" >/dev/null || die "notary profile $NOTARY_PROFILE did not authenticate"
120ok "notary profile $NOTARY_PROFILE authenticates"
121
122# ---- 3. Build ---------------------------------------------------------------
123REUSE=0
124if [[ -e $RECORD ]]; then
125 [[ -f $RECORD/release.json && -f $RECORD/$ZIP ]] || die "$RECORD exists without release.json and $ZIP; inspect and remove it"
126 [[ $(json "$RECORD/release.json" version) == $VERSION && $(json "$RECORD/release.json" build) == $BUILD ]] || die "$RECORD is another release"
127 REUSE=1
128fi
129step "Build Oficina Calls.app $VERSION ($BUILD), release configuration"
130APP=$NATIVE/build/Oficina\ Calls.app
131if (( REUSE )); then
132 say "skipped: reusing the notarised release in ${RECORD/#$HOME/~}"
133else
134 (cd "$NATIVE" && OFICINA_BUILD_CONFIGURATION=release scripts/build-mac.sh \
135 --updates-config mac-updates.json --version "$VERSION" --build "$BUILD" --sign-identity "$IDENTITY")
136 [[ $(plist "$APP" CFBundleIdentifier) == $BUNDLE_ID ]] || die "built app is not $BUNDLE_ID"
137 [[ $(plist "$APP" CFBundleShortVersionString) == $VERSION && $(plist "$APP" CFBundleVersion) == $BUILD ]] || die "built app is not $VERSION ($BUILD)"
138 ok "${APP/#$HOME/~} is $BUNDLE_ID $VERSION ($BUILD)"
139fi
140
141# ---- 4. Sign, notarise, staple, EdDSA (release_mac.py) -------------------------
142step "release_mac.py: sign inside out, notarise, staple, Gatekeeper, Sparkle archive"
143if (( ! REUSE )); then
144 say "notarisation usually takes a few minutes"
145 python3 "$TOOLS/release_mac.py" "$APP" --config "$CONFIG" --sparkle-tools "$SPARKLE_BIN" \
146 --identity "$IDENTITY" --team "$TEAM" --notary-profile "$NOTARY_PROFILE" --output "$RECORD"
147fi
148SHA=$(json "$RECORD/release.json" sha256); LEN=$(json "$RECORD/release.json" length)
149[[ $(shasum -a 256 "$RECORD/$ZIP" | cut -d' ' -f1) == $SHA ]] || die "$ZIP's digest differs from release.json"
150ok "$ZIP: $LEN bytes, sha256 $SHA, notarisation $(json "$RECORD/release.json" notarization_id)"
151say "entitlements: $(python3 -c 'import json,sys; print(", ".join(sorted(json.load(open(sys.argv[1]))["entitlements"])))' "$RECORD/release.json")"
152
153# ---- 5. The download, as a person gets it ----------------------------------------
154step "Smoke test: quarantined copy, names, Gatekeeper, translocated launch for 20 s"
155SMOKE=$TMP/smoke
156mkdir -p "$SMOKE"
157ditto -x -k "$RECORD/$ZIP" "$SMOKE"
158apps=("$SMOKE"/*.app(N))
159(( ${#apps} == 1 )) || die "the archive holds ${#apps} apps, not one"
160GOT=${apps[1]}
161[[ ${GOT:t} == "Oficina Calls.app" ]] || die "the archive holds ${GOT:t}, not Oficina Calls.app"
162for pair in CFBundleIdentifier=$BUNDLE_ID CFBundleDisplayName="Oficina Calls" CFBundleName=Calls SUBundleName=Calls CFBundleIconName=AppIcon; do
163 [[ $(plist "$GOT" ${pair%%=*}) == ${pair#*=} ]] || die "${pair%%=*} is '$(plist "$GOT" ${pair%%=*})', not '${pair#*=}'"
164done
165ok "Oficina Calls.app: $BUNDLE_ID, display name Oficina Calls, CFBundleName and SUBundleName Calls"
166[[ -f $GOT/Contents/Resources/Assets.car ]] || die "no Assets.car"
167[[ -d $GOT/Contents/Resources/RastrilloNative_RastrilloApple.bundle ]] || die "no RastrilloApple resources (the app menu's strings)"
168xattr -w com.apple.quarantine "0081;$(printf %x $(date +%s));Safari;" "$GOT"
169xcrun stapler validate "$GOT" >/dev/null || die "no stapled ticket"
170gk=$(spctl --assess --type execute -vv "$GOT" 2>&1) || die "Gatekeeper rejected the app: $gk"
171[[ $gk == *"source=Notarized Developer ID"* && $gk == *"origin=$IDENTITY"* ]] || die "unexpected Gatekeeper verdict: $gk"
172ok "Gatekeeper: accepted, Notarized Developer ID, $TEAM"
173say "launching; if macOS asks whether to open an app downloaded from the Internet, click Open"
174open -n "$GOT"
175for _ in {1..60}; do
176 SMOKE_PID=$(pgrep -f 'AppTranslocation/.*/Oficina Calls\.app/Contents/MacOS/CallsMac' | head -1 || true)
177 [[ -n $SMOKE_PID ]] && break
178 sleep 1
179done
180[[ -n $SMOKE_PID ]] || die "the translocated app did not start within 60 s"
181sleep 20
182kill -0 "$SMOKE_PID" 2>/dev/null || die "the app quit within 20 s of launch"
183ok "ran translocated for 20 s (pid $SMOKE_PID)"
184kill "$SMOKE_PID" 2>/dev/null || true
185SMOKE_PID=""
186
187# ---- 6. The publisher's plan (read-only) ------------------------------------------
188step "publish_mac_update.py plan (validates; changes nothing)"
189if [[ -n $ARTIFACTS && -d $ARTIFACTS/.git ]]; then
190 python3 "$TOOLS/publish_mac_update.py" "$RECORD" --config "$CONFIG" --repo "$ARTIFACTS" --sparkle-tools "$SPARKLE_BIN"
191else
192 warn "no native-releases clone at '${ARTIFACTS:-unset}'; the publisher's plan was not checked"
193fi
194
195cat <<EOF
196
197----- Oficina Calls $VERSION ($BUILD): ready to publish, NOT published -----
198commit: $COMMIT
199release: $RECORD
200archive: $ZIP $LEN bytes sha256 $SHA
201feed: $FEED_URL (newest now $newest)
202notes: ${(j:; :)NOTES:-none}
203
204Publish (pushes tag calls-$BUILD, uploads the zip, commits the appcast), with
205git and amadan as the agent (native/README.md, "Releasing the Mac app"):
206 python3 $TOOLS/publish_mac_update.py \\
207 $RECORD \\
208 --config $CONFIG --repo ${ARTIFACTS:-<native-releases clone>} \\
209 --sparkle-tools $SPARKLE_BIN --publish
210------------------------------------------------------------------------
211EOF
212