Branchwell

Textley / app · textley.ai / Scripts / release-app.sh

1#!/bin/bash
2set -euo pipefail
3umask 022
4
5# Builds the Developer ID app with Sparkle, packages the branded DMG, notarizes and staples it,
6# and writes the signed appcast.xml and SHA256SUMS next to it.
7# Usage: Scripts/release-app.sh RELEASE_DIRECTORY NOTARYTOOL_OPTIONS...
8# e.g. Scripts/release-app.sh ~/Releases/Textley/1.1.0 --keychain-profile "$NOTARYTOOL_PROFILE"
9root="$(cd "$(dirname "$0")/.." && pwd)"
10output="${1:?Usage: Scripts/release-app.sh RELEASE_DIRECTORY NOTARYTOOL_OPTIONS...}"
11shift
12[[ $# -gt 0 ]] || { echo 'Pass notarytool authentication options, such as --keychain-profile NAME.' >&2; exit 1; }
13[[ ! -e "$output/Textley.app" ]] || { echo 'Choose a fresh release directory.' >&2; exit 1; }
14export TEXTLEY_SIGN_IDENTITY="${TEXTLEY_SIGN_IDENTITY:-Developer ID Application: Protomota, LLC (22HV69L32T)}"
15python="${TEXTLEY_DMG_PYTHON:-python3}"
16"$python" -c 'import dmgbuild' 2>/dev/null || {
17 echo "Install the DMG tools first: $python -m pip install -r Packaging/macOS/requirements.txt" >&2; exit 1; }
18
19TEXTLEY_RELEASE=1 "$root/Scripts/build-app.sh" "$output" release >/dev/null
20app="$output/Textley.app"
21version="$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "$app/Contents/Info.plist")"
22image="$output/Textley-$version.dmg"
23packager=("$python" "$root/Scripts/package-mac-dmg.py" --app "$app" --output "$image")
24"${packager[@]}"
25
26codesign --force --timestamp --sign "$TEXTLEY_SIGN_IDENTITY" "$image"
27xcrun notarytool submit "$image" "$@" --wait --output-format json > "${image%.dmg}.notarization.json"
28/usr/bin/plutil -extract status raw -expect string "${image%.dmg}.notarization.json" | /usr/bin/grep -Fx Accepted
29xcrun stapler staple "$image"
30codesign --verify --strict "$image"
31xcrun stapler validate "$image"
32spctl --assess --type open --context context:primary-signature --verbose=2 "$image"
33"${packager[@]}" --verify-only
34
35sparkle="$(bash "$root/Scripts/prepare-sparkle.sh" "$output/sparkle")"
36account=textley-direct
37public_key="$(/usr/libexec/PlistBuddy -c 'Print SUPublicEDKey' "$app/Contents/Info.plist")"
38[[ "$("$sparkle/bin/generate_keys" --account "$account" -p)" == "$public_key" ]] || {
39 echo 'The Sparkle signing key does not match this app.' >&2; exit 1; }
40feed="$output/feed"
41mkdir -p "$feed"
42cp "$image" "$feed/"
43"$sparkle/bin/generate_appcast" --account "$account" --maximum-deltas 0 \
44 --download-url-prefix https://textley.ai/downloads/ -o "$output/appcast.xml" "$feed"
45signature="$(xmllint --xpath 'string(//enclosure/@*[local-name()="edSignature"])' "$output/appcast.xml")"
46"$sparkle/bin/sign_update" --account "$account" --verify "$image" "$signature"
47"$sparkle/bin/sign_update" --account "$account" --verify "$output/appcast.xml"
48(cd "$output" && shasum -a 256 "$(basename "$image")" > SHA256SUMS)
49printf '%s\n' "$image"