Textley / app · textley.ai / Scripts / release-app.sh
| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | umask 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" |
| 9 | root="$(cd "$(dirname "$0")/.." && pwd)" |
| 10 | output="${1:?Usage: Scripts/release-app.sh RELEASE_DIRECTORY NOTARYTOOL_OPTIONS...}" |
| 11 | shift |
| 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; } |
| 14 | export TEXTLEY_SIGN_IDENTITY="${TEXTLEY_SIGN_IDENTITY:-Developer ID Application: Protomota, LLC (22HV69L32T)}" |
| 15 | python="${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 | |
| 19 | TEXTLEY_RELEASE=1 "$root/Scripts/build-app.sh" "$output" release >/dev/null |
| 20 | app="$output/Textley.app" |
| 21 | version="$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "$app/Contents/Info.plist")" |
| 22 | image="$output/Textley-$version.dmg" |
| 23 | packager=("$python" "$root/Scripts/package-mac-dmg.py" --app "$app" --output "$image") |
| 24 | "${packager[@]}" |
| 25 | |
| 26 | codesign --force --timestamp --sign "$TEXTLEY_SIGN_IDENTITY" "$image" |
| 27 | xcrun 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 |
| 29 | xcrun stapler staple "$image" |
| 30 | codesign --verify --strict "$image" |
| 31 | xcrun stapler validate "$image" |
| 32 | spctl --assess --type open --context context:primary-signature --verbose=2 "$image" |
| 33 | "${packager[@]}" --verify-only |
| 34 | |
| 35 | sparkle="$(bash "$root/Scripts/prepare-sparkle.sh" "$output/sparkle")" |
| 36 | account=textley-direct |
| 37 | public_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; } |
| 40 | feed="$output/feed" |
| 41 | mkdir -p "$feed" |
| 42 | cp "$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" |
| 45 | signature="$(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) |
| 49 | printf '%s\n' "$image" |