Jotley / app · jotley.ai / scripts / release-local.sh
| 1 | #!/bin/zsh |
| 2 | set -euo pipefail |
| 3 | |
| 4 | usage() { |
| 5 | print -u2 'Usage: zsh scripts/release-local.sh {ios|mac} BUILD SIGNING_XCCONFIG OUTPUT_DIR [IOS_EXPORT_OPTIONS]' |
| 6 | exit 2 |
| 7 | } |
| 8 | if (( $# < 4 || $# > 5 )) || [[ "$1" != (ios|mac) || "$2" != <1-> ]]; then usage; fi |
| 9 | |
| 10 | platform="$1" |
| 11 | build="$2" |
| 12 | config="${3:A}" |
| 13 | output="${4:A}" |
| 14 | repo="${0:A:h:h}" |
| 15 | if [[ "$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 |
| 18 | fi |
| 19 | if [[ "$platform" == ios ]]; then |
| 20 | if (( $# != 5 )) || [[ ! -r "$5" ]]; then usage; fi |
| 21 | else |
| 22 | if (( $# != 4 )); then usage; fi |
| 23 | fi |
| 24 | mkdir -p "$output/tmp" |
| 25 | export TMPDIR="$output/tmp" |
| 26 | args=(-project "$repo/Jotley.xcodeproj" -configuration Release -xcconfig "$config" |
| 27 | -derivedDataPath "${JOTLEY_DERIVED_DATA:-$output/DerivedData}") |
| 28 | if [[ -n "${JOTLEY_PACKAGES_PATH:-}" ]]; then |
| 29 | args+=(-clonedSourcePackagesDirPath "$JOTLEY_PACKAGES_PATH" -disableAutomaticPackageResolution) |
| 30 | fi |
| 31 | |
| 32 | if [[ "$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 |
| 41 | fi |
| 42 | |
| 43 | products="$output/products" |
| 44 | xcodebuild "${args[@]}" -scheme Jotley -destination 'platform=macOS,arch=arm64' \ |
| 45 | CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO CONFIGURATION_BUILD_DIR="$products" build |
| 46 | app="$output/Jotley.app" |
| 47 | ditto "$products/Jotley.app" "$app" |
| 48 | info="$app/Contents/Info.plist" |
| 49 | [[ "$(plutil -extract CFBundleVersion raw -o - "$info")" == "$build" ]] |
| 50 | version="$(plutil -extract CFBundleShortVersionString raw -o - "$info")" |
| 51 | codesign --display --entitlements :- "$app" > "$output/app-entitlements.plist" |
| 52 | if /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 |
| 55 | fi |
| 56 | identity="${JOTLEY_MAC_RELEASE_IDENTITY:?Set the existing Developer ID Application certificate name or SHA-1.}" |
| 57 | identity="$(python3 "$repo/scripts/signing_identity.py" "$identity" --kind developer-id)" |
| 58 | keychain="$HOME/Library/Keychains/login.keychain-db" |
| 59 | sign() { codesign --force --sign "$identity" --keychain "$keychain" --options runtime --timestamp "$@"; } |
| 60 | cp "$repo/packaging/macos/background.tiff" "$app/Contents/Resources/JotleyInstallerBackground.tiff" |
| 61 | sparkle="$app/Contents/Frameworks/Sparkle.framework" |
| 62 | for component in Autoupdate Updater.app XPCServices/Downloader.xpc XPCServices/Installer.xpc; do |
| 63 | sign "$sparkle/Versions/B/$component" |
| 64 | done |
| 65 | sign "$sparkle" |
| 66 | sign --entitlements "$output/app-entitlements.plist" "$app" |
| 67 | codesign --verify --deep --strict "$app" |
| 68 | zip="$output/Jotley-$version-$build-app.zip" |
| 69 | dmg="$output/Jotley-$version-$build.dmg" |
| 70 | ditto -c -k --keepParent "$app" "$zip" |
| 71 | python3 "$repo/scripts/release-local-delivery.py" notarize "$zip" "$output/app-notarization.json" |
| 72 | xcrun stapler staple "$app" |
| 73 | xcrun stapler validate "$app" |
| 74 | spctl --assess --type execute "$app" |
| 75 | packaging_python="${JOTLEY_PACKAGING_PYTHON:-python3}" |
| 76 | "$packaging_python" "$repo/scripts/package-mac-dmg.py" --app "$app" --output "$dmg" |
| 77 | codesign --force --sign "$identity" --keychain "$keychain" --timestamp "$dmg" |
| 78 | python3 "$repo/scripts/release-local-delivery.py" notarize "$dmg" "$output/dmg-notarization.json" |
| 79 | xcrun stapler staple "$dmg" |
| 80 | xcrun stapler validate "$dmg" |
| 81 | codesign --verify --strict "$dmg" |
| 82 | spctl --assess --type open --context context:primary-signature "$dmg" |
| 83 | "$packaging_python" "$repo/scripts/package-mac-dmg.py" --app "$app" --output "$dmg" --verify-only |
| 84 | shasum -a 256 "$dmg" |
| 85 | print -r -- "Notarized Mac installer: $dmg" |