scripts/release-macos.sh

design-themes-widgets
orgstar/scripts/release-macos.sh history · blame · raw

68 lines · 4058 bytes · executable

 1#!/bin/sh
 2# Archives the Mac App Store app (with its widgets, Quick Look and Spotlight extensions) and uploads
 3# it to App Store Connect. The version is the project's MARKETING_VERSION; the build number is the
 4# commit count. The Developer ID app is released by scripts/release-mac.sh instead. The work is done
 5# by appstore-kit, checked out beside this repository or at $APPSTORE_KIT.
 6# Usage: scripts/release-macos.sh
 7#   ORGSTAR_PUBLISH  0 archives and exports the .pkg to .build/macos-release without uploading
 8PUBLISH="${ORGSTAR_PUBLISH:-1}"
 9name=orgstar
10project=ios/Orgstar.xcodeproj
11scheme="Orgstar macOS"
12platform=macos
13configuration=Release
14
15# Runs before the archive, so it can only check build settings; then the performance gates.
16preflight() {
17    settings="$(command xcodebuild -project "$project" -scheme "$scheme" -configuration "$configuration" \
18        -destination 'generic/platform=macOS' -showBuildSettings 2>/dev/null)" || fail "can't read the build settings of $scheme"
19    value() {
20        printf '%s\n' "$settings" | sed -n "s/^ *$1 = //p" | head -1
21    }
22    case " $(value SWIFT_ACTIVE_COMPILATION_CONDITIONS) " in
23        *" APPSTORE "*) ;;
24        *) fail "SWIFT_ACTIVE_COMPILATION_CONDITIONS of $scheme ($configuration) lacks APPSTORE" ;;
25    esac
26    [ "$(value PRODUCT_BUNDLE_IDENTIFIER)" = sh.krz.orgstar ] || fail "$scheme's bundle ID is $(value PRODUCT_BUNDLE_IDENTIFIER), not sh.krz.orgstar"
27    for entitlements in ios/OrgstarMac/*.entitlements ios/OrgstarWidgets/*-macOS.entitlements \
28        ios/OrgstarQuickLook/*-macOS.entitlements ios/OrgstarSpotlight/*.entitlements; do
29        ! grep -q temporary-exception "$entitlements" || fail "$entitlements has a temporary exception"
30    done
31    ORGSTAR_GATES=1 swift test -c release --filter GateTests || fail "a performance gate failed"
32}
33
34# Checks the built app: no Sparkle, no updater keys, no process launching, no temporary exceptions,
35# and no license or update text in its string tables. Provisioning profiles aren't checked here: the
36# archive is signed for development, which gives extensions without capabilities none, and the
37# export signs every bundle again with a distribution profile.
38check_archive() {
39    set -- "$1"/Products/Applications/*.app
40    [ -d "$1" ] || fail "no app in the archive"
41    app="$1"
42    [ -z "$(find "$app" -iname '*sparkle*' | head -1)" ] || fail "the archive contains Sparkle: $(find "$app" -iname '*sparkle*' | head -1)"
43    keys="$(plutil -convert json -o - "$app/Contents/Info.plist" \
44        | python3 -c 'import json, sys; print(" ".join(k for k in json.load(sys.stdin) if k.startswith("SU")))')"
45    [ -z "$keys" ] || fail "Info.plist has Sparkle keys: $keys"
46    for bundle in "$app" "$app"/Contents/PlugIns/*.appex "$app"/Contents/Extensions/*.appex; do
47        [ -d "$bundle" ] || continue
48        executable="$bundle/Contents/MacOS/$(/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "$bundle/Contents/Info.plist")"
49        symbols="$(nm -u "$executable" | grep -E '_OBJC_CLASS_\$_NSTask$|_posix_spawnp?$' | sort -u | tr '\n' ' ')"
50        [ -z "$symbols" ] || fail "$(basename "$bundle") launches processes: $symbols"
51        entitlements="$(codesign -d --entitlements - --xml "$bundle" 2>/dev/null)" || fail "$(basename "$bundle") isn't signed"
52        case "$entitlements" in
53            *temporary-exception*) fail "$(basename "$bundle") has a temporary-exception entitlement" ;;
54        esac
55    done
56    found="$(find "$app" -path '*.lproj/*' -name '*.strings' -exec sh -c \
57        'plutil -convert json -o - "$1" | grep -Eio "sponsor|license key|krz\.sh|check for updates" | sed "s|^|$1: |"' _ {} \; | head -1)"
58    [ -z "$found" ] || fail "the app has Developer ID text: $found"
59}
60
61# appstore-kit has no step between archiving and exporting, so its export call checks the archive first.
62xcodebuild() {
63    if [ "$1" = -exportArchive ] && [ "$2" = -archivePath ]; then
64        check_archive "$3"
65    fi
66    command xcodebuild "$@"
67}
68. "${APPSTORE_KIT:-$(dirname "$0")/../../appstore-kit}/release-ios.sh"