Optimize DEV workshop deployment cache

This commit is contained in:
2026-07-14 15:56:24 -03:00
parent 1ddc33f4a9
commit 1c735cc840
2 changed files with 187 additions and 82 deletions
+45 -3
View File
@@ -58,6 +58,14 @@ def parse_args() -> argparse.Namespace:
action="store_true",
help="Rebuild every buildable addon, ignoring matching cache hashes.",
)
parser.add_argument(
"--addons",
default=None,
help=(
"Comma-separated addon allowlist to rebuild. When set, only these "
"addons may be rebuilt; unchanged addons are staged from cache."
),
)
parser.add_argument(
"--dry-run",
action="store_true",
@@ -78,6 +86,14 @@ def buildable_addons(root: Path) -> list[str]:
return addons
def parse_addon_allowlist(value: str | None) -> list[str] | None:
if value is None:
return None
addons = [part.strip() for part in value.split(",") if part.strip()]
return sorted(dict.fromkeys(addons))
def file_digest(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
@@ -289,12 +305,24 @@ def main() -> int:
stage_dir = (root / args.stage_dir).resolve()
addons = buildable_addons(root)
requested_addons = parse_addon_allowlist(args.addons)
if requested_addons is not None:
unknown_addons = sorted(set(requested_addons) - set(addons))
if unknown_addons:
print(
"ERROR: Requested addon is not buildable: "
+ ", ".join(unknown_addons),
file=sys.stderr,
)
return 2
if args.source_root:
source_root = Path(args.source_root).resolve()
elif args.dry_run:
source_root = (cache_dir / "mikero-source" / "braf").resolve()
else:
source_root = prepare_mikero_source_root(root, cache_dir, addons).resolve()
source_root_addons = requested_addons if requested_addons is not None else addons
source_root = prepare_mikero_source_root(root, cache_dir, source_root_addons).resolve()
current_hashes = {addon: addon_digest(root / addon) for addon in addons}
manifest = load_manifest(manifest_path)
@@ -308,7 +336,8 @@ def main() -> int:
manifest_addons.pop(addon, None)
to_build: list[str] = []
for addon in addons:
candidate_addons = requested_addons if requested_addons is not None else addons
for addon in candidate_addons:
cached_hash = manifest_addons.get(addon, {}).get("hash")
if (
args.force_rebuild
@@ -318,6 +347,11 @@ def main() -> int:
to_build.append(addon)
print(f"Buildable addons: {len(addons)}")
if requested_addons is not None:
print(
"Requested rebuild allowlist: "
+ (", ".join(requested_addons) if requested_addons else "none")
)
print(f"Addons to build: {', '.join(to_build) if to_build else 'none'}")
print(f"Cache dir: {cache_dir}")
print(f"Stage dir: {stage_dir}")
@@ -336,7 +370,15 @@ def main() -> int:
for addon in addons:
if not cached_pbo_exists(cache_addons_dir, addon):
raise RuntimeError(f"Cache does not contain required PBO after build: {addon}")
hint = (
" Seed the persistent cache first or include this addon in the "
"detected rebuild set."
if requested_addons is not None and addon not in candidate_addons
else ""
)
raise RuntimeError(
f"Cache does not contain required PBO after build: {addon}.{hint}"
)
stage_package(root, stage_dir, cache_addons_dir, addons)
write_manifest(manifest_path, manifest)