|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import os |
| 4 | +import sys |
| 5 | +import time |
| 6 | +import xml.etree.ElementTree as ET |
| 7 | + |
| 8 | +if os.environ.get("SIGN", "") == "0": |
| 9 | + print("SIGN=0 via environment, skipping notarization step") |
| 10 | + sys.exit(0) |
| 11 | +if os.environ.get("NOTARIZE", "") == "0": |
| 12 | + print("NOTARIZE=0 via environment, skipping notarization step") |
| 13 | + sys.exit(0) |
| 14 | +if not os.environ.get("APPLE_ID_USER", ""): |
| 15 | + print("APPLE_ID_USER not specified, skipping notarization step") |
| 16 | + sys.exit(0) |
| 17 | + |
| 18 | +app = sys.argv[1] |
| 19 | +app_id = sys.argv[2] |
| 20 | + |
| 21 | +apple_id_user = os.environ.get("APPLE_ID_USER", "") |
| 22 | +itc_provider = os.environ.get("ITC_PROVIDER", "") |
| 23 | +if os.path.exists(".env"): |
| 24 | + f = open(".env", "r") |
| 25 | + for line in f: |
| 26 | + line = line.strip() |
| 27 | + if not line: |
| 28 | + continue |
| 29 | + key, value = line.split("=") |
| 30 | + os.environ[key] = value |
| 31 | + if key == "APPLE_ID_USER": |
| 32 | + apple_id_user = value |
| 33 | + if key == "ITC_PROVIDER": |
| 34 | + itc_provider = value |
| 35 | + |
| 36 | + |
| 37 | +def shell(cmd): |
| 38 | + print(cmd) |
| 39 | + return os.popen(cmd).read() |
| 40 | + |
| 41 | + |
| 42 | +shell("rm -f Notarize.zip") |
| 43 | +shell("zip -r Notarize.zip \"{}\"".format(app)) |
| 44 | +result = shell("xcrun altool --notarize-app -t osx -f Notarize.zip " \ |
| 45 | +"--primary-bundle-id {} -u {} -p @env:APPLE_ID_PASS " \ |
| 46 | +"-itc_provider {} --output-format xml".format( |
| 47 | + app_id, apple_id_user, itc_provider)) |
| 48 | + |
| 49 | +print(result) |
| 50 | +root = ET.fromstring(result) |
| 51 | +dict = root.find("dict") |
| 52 | +print(dict) |
| 53 | +request_uuid = dict.find("dict").find("string").text |
| 54 | +print(request_uuid) |
| 55 | + |
| 56 | +while True: |
| 57 | + time.sleep(10.0) |
| 58 | + result = shell("xcrun altool --notarization-info {} " \ |
| 59 | + "-u {} -p @env:APPLE_ID_PASS " \ |
| 60 | + "-itc_provider {} --output-format xml".format( |
| 61 | + request_uuid, apple_id_user, itc_provider)) |
| 62 | + if "<string>success</string>" in result: |
| 63 | + break |
| 64 | + elif "<string>in progress</string>" in result: |
| 65 | + print("in progress...") |
| 66 | + continue |
| 67 | + else: |
| 68 | + print(result) |
| 69 | + raise Exception("...") |
| 70 | + |
| 71 | +print("xcrun stapler staple \"{}\"".format(app)) |
| 72 | +assert os.system("xcrun stapler staple \"{}\"".format(app)) == 0 |
| 73 | +shell("rm Notarize.zip") |
0 commit comments