Files
ara/sync.sh
T

49 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env python3
"""
ARA Aggregator Sync
Reads catalog.yaml and sparse-checkouts ara/ from each source repo.
Run this after PRs merge to update the aggregator from canonical sources.
"""
import yaml, subprocess, shutil, os, sys
with open(os.path.join(os.path.dirname(__file__), "catalog.yaml")) as f:
catalog = yaml.safe_load(f)
errors = []
for artifact in catalog["artifacts"]:
if artifact["status"] == "aggregator-only":
print(f" skip {artifact['id']} (aggregator-only)")
continue
if "pr-open" in artifact["status"] or "stub" in artifact["status"]:
print(f" skip {artifact['id']} (PR not yet merged: {artifact.get('pr','')})")
continue
id, repo, branch, path = (
artifact["id"], artifact["repo"],
artifact["branch"], artifact["path"].rstrip("/"),
)
print(f"syncing {id} from {repo} ({branch}:{path}) ...")
tmp = f"/tmp/ara-sync-{id}"
try:
shutil.rmtree(tmp, ignore_errors=True)
subprocess.run(
["git","clone","--no-checkout","--filter=blob:none","--depth=1","-b",branch,repo,tmp],
check=True, capture_output=True,
)
subprocess.run(["git","sparse-checkout","init","--cone"], cwd=tmp, check=True, capture_output=True)
subprocess.run(["git","sparse-checkout","set",path], cwd=tmp, check=True, capture_output=True)
subprocess.run(["git","checkout"], cwd=tmp, check=True, capture_output=True)
dest = id
shutil.rmtree(dest, ignore_errors=True)
shutil.copytree(f"{tmp}/{path}", dest)
shutil.rmtree(tmp, ignore_errors=True)
print(f" ok: {id}")
except Exception as e:
errors.append((id, str(e)))
print(f" ERROR: {id}: {e}", file=sys.stderr)
if errors:
print(f"\nFailed: {[e[0] for e in errors]}", file=sys.stderr)
sys.exit(1)
print("Sync complete.")