PulseCanvas / app · pulsecanvas.ai / scripts / release-direct-dmg.sh
| 1 | #!/bin/bash |
| 2 | # Local direct-download packaging; does not publish or submit an App Store build. |
| 3 | set -euo pipefail |
| 4 | cd "$(dirname "$0")/.." |
| 5 | # Notarize with an existing notarytool Keychain profile, or with an App Store Connect API key |
| 6 | # from APPLE_API_KEY (private key path), APPLE_API_KEY_ID and APPLE_API_ISSUER (pass "api-key"). |
| 7 | profile="${1:-${NOTARYTOOL_PROFILE:-}}" |
| 8 | resume="${2:-}" |
| 9 | [[ -n "$profile" && ( -z "$resume" || "$resume" == --resume ) ]] || { echo 'Usage: scripts/release-direct-dmg.sh EXISTING_NOTARYTOOL_KEYCHAIN_PROFILE|api-key [--resume]' >&2; exit 1; } |
| 10 | if [[ "$profile" == api-key ]]; then |
| 11 | : "${APPLE_API_KEY:?Set the App Store Connect private key path.}" |
| 12 | : "${APPLE_API_KEY_ID:?Set the App Store Connect key ID.}" |
| 13 | : "${APPLE_API_ISSUER:?Set the App Store Connect issuer ID.}" |
| 14 | notary_credentials=(--key "$APPLE_API_KEY" --key-id "$APPLE_API_KEY_ID" --issuer "$APPLE_API_ISSUER") |
| 15 | else |
| 16 | notary_credentials=(--keychain-profile "$profile") |
| 17 | fi |
| 18 | identity="${DEVELOPER_ID_APPLICATION:-Developer ID Application: Protomota, LLC (22HV69L32T)}" |
| 19 | python="${DMG_PYTHON:-$PWD/.build/dmg-tools/bin/python}" |
| 20 | [[ -x "$python" ]] || { echo 'Prepare Python 3.12 build tools as documented in packaging/macos/README.md.' >&2; exit 1; } |
| 21 | "$python" -c 'import sys; from importlib.metadata import version; assert sys.version_info[:2] == (3,12); assert all(version(k)==v for k,v in {"dmgbuild":"1.6.7","ds-store":"1.3.3","mac-alias":"2.2.3"}.items())' |
| 22 | # DIRECT_APP permits finishing an already-built signed bundle without rebuilding. |
| 23 | if [[ -z "${DIRECT_APP:-}" && "$resume" != --resume ]]; then |
| 24 | ./scripts/build-direct-release.sh |
| 25 | fi |
| 26 | app="${DIRECT_APP:-$PWD/build/direct/PulseCanvas Studio.app}" |
| 27 | version=$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "$app/Contents/Info.plist") |
| 28 | build=$(/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' "$app/Contents/Info.plist") |
| 29 | image="${DIRECT_DMG:-$PWD/build/direct-distribution/PulseCanvas-Studio-$version-$build.dmg}" |
| 30 | if [[ "$resume" == --resume ]]; then |
| 31 | [[ -f "$image" ]] || { echo "No image to resume: $image" >&2; exit 1; } |
| 32 | # Prove that the existing image is an exact copy of the signed source bundle. |
| 33 | "$python" scripts/package-mac-dmg.py --app "$app" --output "$image" --verify-only |
| 34 | else |
| 35 | [[ ! -e "$image" ]] || { echo "Output exists: $image; set DIRECT_DMG to a fresh path or use --resume." >&2; exit 1; } |
| 36 | "$python" scripts/package-mac-dmg.py --app "$app" --output "$image" |
| 37 | fi |
| 38 | if [[ "$resume" == --resume ]] && codesign --verify --strict "$image" && \ |
| 39 | codesign --display --verbose=2 "$image" 2>&1 | /usr/bin/grep -Fx "Authority=$identity" >/dev/null; then |
| 40 | echo 'Retaining the verified existing Developer ID image signature.' |
| 41 | else |
| 42 | codesign --force --timestamp --sign "$identity" "$image" |
| 43 | fi |
| 44 | xcrun notarytool submit "$image" "${notary_credentials[@]}" --wait --output-format json > "${image%.dmg}.notarization.json" |
| 45 | "$python" - "${image%.dmg}.notarization.json" <<'PY' |
| 46 | import json, sys |
| 47 | result = json.load(open(sys.argv[1])) |
| 48 | if result.get('status') != 'Accepted': |
| 49 | raise SystemExit(f"Apple notarization did not accept the DMG: {result.get('status')}") |
| 50 | print('Apple notarization: Accepted') |
| 51 | PY |
| 52 | xcrun stapler staple "$image" |
| 53 | xcrun stapler validate "$image" |
| 54 | codesign --verify --strict --verbose=2 "$image" |
| 55 | spctl --assess --type open --context context:primary-signature --verbose=2 "$image" |
| 56 | "$python" scripts/package-mac-dmg.py --app "$app" --output "$image" --verify-only --release-checks |
| 57 | account=$(python3 -c 'import json; print(json.load(open("macOS/DirectRelease.json"))["sparkleKeychainAccount"])') |
| 58 | signature=$(.build/sparkle/bin/sign_update --account "$account" -p "$image") |
| 59 | .build/sparkle/bin/sign_update --account "$account" --verify "$image" "$signature" |
| 60 | "$python" - "$app" "$image" "$signature" <<'PY' |
| 61 | import hashlib, json, plistlib, subprocess, sys |
| 62 | from pathlib import Path |
| 63 | app, image, signature = Path(sys.argv[1]), Path(sys.argv[2]), sys.argv[3] |
| 64 | config = json.loads(Path('macOS/DirectRelease.json').read_text()) |
| 65 | subprocess.run(['xcrun', 'swift', 'scripts/verify-update-signature.swift', str(image), signature, config['sparklePublicKey']], check=True) |
| 66 | info = plistlib.loads((app / 'Contents/Info.plist').read_bytes()) |
| 67 | report = {'version': info['CFBundleShortVersionString'], 'build': info['CFBundleVersion'], |
| 68 | 'file': image.name, 'bytes': image.stat().st_size, |
| 69 | 'sha256': hashlib.sha256(image.read_bytes()).hexdigest(), |
| 70 | 'edSignature': signature, 'sparklePublicKeyVerified': True, |
| 71 | 'notarization': 'Accepted', 'stapled': True, 'published': False} |
| 72 | image.with_suffix('.release.json').write_text(json.dumps(report, indent=2) + '\n') |
| 73 | print('Verified local installer:', image) |
| 74 | PY |