@@ -361,6 +361,36 @@ def fetch_ref(value):
361361 run_git(workspace, "checkout", "--detach", "refs/remotes/origin/checkout")
362362
363363
364+ def checkout_harness(sha):
365+ action = ".github/actions/setup-node-env/action.yml"
366+ if kind == "linux-node" and not os.path.isfile(os.path.join(workspace, action)):
367+ raise GitFailure(1)
368+ harness = os.path.join(workspace, ".ci-harness")
369+ os.makedirs(harness, exist_ok=True)
370+ if sha == os.environ["WORKFLOW_SHA"]:
371+ # Export the workflow revision from the freshly populated index, replacing
372+ # retained platform files without updating the index or trusting later edits.
373+ paths = git_output(workspace, "ls-files", "-z", "--", ".github/actions").split("\0")[:-1]
374+ run_git(workspace, "checkout-index", "--force", f"--prefix={harness}/", "--", *paths)
375+ else:
376+ run_git(harness, "init", harness)
377+ run_git(harness, "remote", "add", "origin", remote)
378+ # The harness only supplies .github/actions, so narrow the fetch before it runs:
379+ # sparse first, then blob-less. A full snapshot here downloads a second copy of
380+ # the repository that the checkout below immediately discards, and every extra
381+ # byte is amplified by the shared runner egress.
382+ run_git(harness, "sparse-checkout", "set", ".github/actions")
383+ fetch(harness, f"+{os.environ['WORKFLOW_SHA']}:refs/remotes/origin/ci-harness",
384+ max_attempts=1, blobless=True)
385+ # Checkout now materializes the sparse blobs over the network, so it carries the
386+ # fetch deadline instead of running unbounded like a local checkout.
387+ run_git(harness, "checkout", "--force", "--detach", os.environ["WORKFLOW_SHA"],
388+ timeout=fetch_timeout_seconds)
389+ if not os.path.isfile(os.path.join(harness, action)):
390+ raise GitFailure(1)
391+ check_cancelled()
392+
393+
364394def checkout():
365395 check_cancelled()
366396 prerequisites = json.loads(os.environ.get("CHECKOUT_GIT_COMMITS_JSON", "null")) if kind == "linux-node" else None
@@ -383,6 +413,8 @@ def checkout():
383413 run_git(workspace, "remote", "add", "origin", remote)
384414 if kind in ("preflight", "manual"):
385415 checkout_selected_ref()
416+ if kind == "preflight" and resolve_ref("HEAD") == os.environ["WORKFLOW_SHA"]:
417+ checkout_harness(os.environ["WORKFLOW_SHA"])
386418 return
387419 target = "refs/remotes/origin/ci-target" if kind in ("linux-node", "android") else "refs/remotes/origin/checkout"
388420 sha = "refs/heads/main" if kind == "clawhub" else os.environ["CHECKOUT_SHA"]
@@ -403,27 +435,7 @@ def checkout():
403435 return
404436 if kind in ("clawhub", "skills"):
405437 return
406- action = ".github/actions/setup-node-env/action.yml"
407- if kind == "linux-node" and not os.path.isfile(os.path.join(workspace, action)):
408- raise GitFailure(1)
409- harness = os.path.join(workspace, ".ci-harness")
410- os.makedirs(harness, exist_ok=True)
411- run_git(harness, "init", harness)
412- run_git(harness, "remote", "add", "origin", remote)
413- # The harness only supplies .github/actions, so narrow the fetch before it runs:
414- # sparse first, then blob-less. A full snapshot here downloads a second copy of
415- # the repository that the checkout below immediately discards, and every extra
416- # byte is amplified by the shared runner egress.
417- run_git(harness, "sparse-checkout", "set", ".github/actions")
418- fetch(harness, f"+{os.environ['WORKFLOW_SHA']}:refs/remotes/origin/ci-harness",
419- max_attempts=1, blobless=True)
420- # Checkout now materializes the sparse blobs over the network, so it carries the
421- # fetch deadline instead of running unbounded like a local checkout.
422- run_git(harness, "checkout", "--force", "--detach", os.environ["WORKFLOW_SHA"],
423- timeout=fetch_timeout_seconds)
424- if not os.path.isfile(os.path.join(harness, action)):
425- raise GitFailure(1)
426- check_cancelled()
438+ checkout_harness(sha)
427439
428440
429441def main():
0 commit comments