Branchwell

Jotley / app · jotley.ai / scripts / release-local.sh

Raw 4.0 KB on d2c8e7812d9b8c1cc5857eb6dc912d99bc5c9048
1#!/bin/zsh
2set -euo pipefail
3
4usage() {
5 print -u2 'Usage: zsh scripts/release-local.sh {ios|mac} BUILD SIGNING_XCCONFIG OUTPUT_DIR [IOS_EXPORT_OPTIONS]'
6 exit 2
7}
8if (( $# < 4 || $# > 5 )) || [[ "$1" != (ios|mac) || "$2" != <1-> ]]; then usage; fi
9
10platform="$1"
11build="$2"
12config="${3:A}"
13output="${4:A}"
14repo="${0:A:h:h}"
15if [[ "$output" != /Volumes/Expand/* || ! -d /Volumes/Expand || ! -r "$config" || -e "$output" ]]; then
16 print -u2 'Use an existing signing config and a fresh output directory on the mounted Expand drive.'
17 exit 2
18fi
19if [[ "$platform" == ios ]]; then
20 if (( $# != 5 )) || [[ ! -r "$5" ]]; then usage; fi
21else
22 if (( $# != 4 )); then usage; fi
23fi
24mkdir -p "$output/tmp"
25export TMPDIR="$output/tmp"
26args=(-project "$repo/Jotley.xcodeproj" -configuration Release -xcconfig "$config"
27 -derivedDataPath "${JOTLEY_DERIVED_DATA:-$output/DerivedData}")
28if [[ -n "${JOTLEY_PACKAGES_PATH:-}" ]]; then
29 args+=(-clonedSourcePackagesDirPath "$JOTLEY_PACKAGES_PATH" -disableAutomaticPackageResolution)
30fi
31
32if [[ "$platform" == ios ]]; then
33 archive="$output/Jotley-iOS.xcarchive"
34 xcodebuild "${args[@]}" -scheme Jotley-iOS -destination generic/platform=iOS -archivePath "$archive" archive
35 app="$archive/Products/Applications/Jotley-iOS.app"
36 [[ "$(plutil -extract CFBundleVersion raw -o - "$app/Info.plist")" == "$build" ]]
37 codesign --verify --deep --strict "$app"
38 xcodebuild -exportArchive -archivePath "$archive" -exportPath "$output/export" -exportOptionsPlist "${5:A}"
39 print -r -- "TestFlight archive: $output/export/Jotley-iOS.ipa"
40 exit
41fi
42
43products="$output/products"
44xcodebuild "${args[@]}" -scheme Jotley -destination 'platform=macOS,arch=arm64' \
45 CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO CONFIGURATION_BUILD_DIR="$products" build
46app="$output/Jotley.app"
47ditto "$products/Jotley.app" "$app"
48info="$app/Contents/Info.plist"
49[[ "$(plutil -extract CFBundleVersion raw -o - "$info")" == "$build" ]]
50version="$(plutil -extract CFBundleShortVersionString raw -o - "$info")"
51codesign --display --entitlements :- "$app" > "$output/app-entitlements.plist"
52if /usr/libexec/PlistBuddy -c 'Print :com.apple.security.get-task-allow' "$output/app-entitlements.plist" >/dev/null 2>&1; then
53 print -u2 'Distribution cannot use an app signed with get-task-allow.'
54 exit 1
55fi
56identity="${JOTLEY_MAC_RELEASE_IDENTITY:?Set the existing Developer ID Application certificate name or SHA-1.}"
57identity="$(python3 "$repo/scripts/signing_identity.py" "$identity" --kind developer-id)"
58keychain="$HOME/Library/Keychains/login.keychain-db"
59sign() { codesign --force --sign "$identity" --keychain "$keychain" --options runtime --timestamp "$@"; }
60cp "$repo/packaging/macos/background.tiff" "$app/Contents/Resources/JotleyInstallerBackground.tiff"
61sparkle="$app/Contents/Frameworks/Sparkle.framework"
62for component in Autoupdate Updater.app XPCServices/Downloader.xpc XPCServices/Installer.xpc; do
63 sign "$sparkle/Versions/B/$component"
64done
65sign "$sparkle"
66sign --entitlements "$output/app-entitlements.plist" "$app"
67codesign --verify --deep --strict "$app"
68zip="$output/Jotley-$version-$build-app.zip"
69dmg="$output/Jotley-$version-$build.dmg"
70ditto -c -k --keepParent "$app" "$zip"
71python3 "$repo/scripts/release-local-delivery.py" notarize "$zip" "$output/app-notarization.json"
72xcrun stapler staple "$app"
73xcrun stapler validate "$app"
74spctl --assess --type execute "$app"
75packaging_python="${JOTLEY_PACKAGING_PYTHON:-python3}"
76"$packaging_python" "$repo/scripts/package-mac-dmg.py" --app "$app" --output "$dmg"
77codesign --force --sign "$identity" --keychain "$keychain" --timestamp "$dmg"
78python3 "$repo/scripts/release-local-delivery.py" notarize "$dmg" "$output/dmg-notarization.json"
79xcrun stapler staple "$dmg"
80xcrun stapler validate "$dmg"
81codesign --verify --strict "$dmg"
82spctl --assess --type open --context context:primary-signature "$dmg"
83"$packaging_python" "$repo/scripts/package-mac-dmg.py" --app "$app" --output "$dmg" --verify-only
84shasum -a 256 "$dmg"
85print -r -- "Notarized Mac installer: $dmg"