Skip to content

Commit 955798c

Browse files
committed
fix: parallelize some jobs
1 parent d697b14 commit 955798c

1 file changed

Lines changed: 37 additions & 13 deletions

File tree

sign.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import string
1717
import tempfile
1818
import json
19+
from multiprocessing.pool import ThreadPool
1920

2021
secret_url = os.path.expandvars("$SECRET_URL").strip().rstrip("/")
2122
secret_key = os.path.expandvars("$SECRET_KEY")
@@ -54,6 +55,14 @@ def run_process(
5455
return result
5556

5657

58+
def run_process_async(
59+
*cmd: str,
60+
env: Optional[Mapping[str, str]] = None,
61+
cwd: Optional[str] = None,
62+
):
63+
return subprocess.Popen(cmd, env=env, cwd=cwd, stdout=PIPE, stderr=PIPE)
64+
65+
5766
def rand_str(len: int, seed: Any = None):
5867
old_state: object = None
5968
if seed is not None:
@@ -272,7 +281,7 @@ def codesign_async(identity: str, component: Path, entitlements: Optional[Path]
272281
cmd = ["codesign", "--continue", "-f", "--no-strict", "-s", identity]
273282
if entitlements:
274283
cmd.extend(["--entitlements", str(entitlements)])
275-
return subprocess.Popen([*cmd, str(component)], stdout=PIPE, stderr=PIPE)
284+
return run_process_async(*cmd, str(component))
276285

277286

278287
def clean_dev_portal_name(name: str):
@@ -342,19 +351,28 @@ def fastlane_register_app_extras(
342351
id if id.startswith(extra_prefix) else extra_prefix + id[id.index(".") + 1 :] for id in matched_ids
343352
)
344353

354+
jobs: List[Popen[bytes]] = []
355+
345356
for id in matched_ids:
346-
run_process(
347-
"fastlane",
348-
"produce",
349-
extra_type,
350-
"--skip_itc",
351-
"-g",
352-
id,
353-
"-n",
354-
clean_dev_portal_name(f"ST {id}"),
355-
env=my_env,
357+
jobs.append(
358+
run_process_async(
359+
"fastlane",
360+
"produce",
361+
extra_type,
362+
"--skip_itc",
363+
"-g",
364+
id,
365+
"-n",
366+
clean_dev_portal_name(f"ST {id}"),
367+
env=my_env,
368+
)
356369
)
357370

371+
for pipe in jobs:
372+
if pipe.poll() is None:
373+
pipe.wait()
374+
popen_check(pipe)
375+
358376
run_process(
359377
"fastlane",
360378
"produce",
@@ -464,8 +482,14 @@ def fastlane_register_app(
464482
env=my_env,
465483
)
466484

467-
fastlane_register_app_extras(my_env, bundle_id, "cloud_container", "iCloud.", icloud_entitlements, entitlements)
468-
fastlane_register_app_extras(my_env, bundle_id, "group", "group.", group_entitlements, entitlements)
485+
app_extras = [("cloud_container", "iCloud."), ("group", "group.")]
486+
with ThreadPool(len(app_extras)) as p:
487+
p.starmap(
488+
lambda extra_type, extra_prefix: fastlane_register_app_extras(
489+
my_env, bundle_id, extra_type, extra_prefix, icloud_entitlements, entitlements
490+
),
491+
app_extras,
492+
)
469493

470494

471495
def fastlane_get_prov_profile(

0 commit comments

Comments
 (0)