This repository has been archived on 2026-11-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
qqq-orb/scripts/pack_pipeline.py

27 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Embed profile resources before Circle packs/interpolates its own syntax."""
import base64
from pathlib import Path
import sys
import zlib
root = Path(__file__).resolve().parents[1]
source = root / "src/scripts/generate_pipeline.py"
output = root / "src/scripts/packed_generate_pipeline.py"
text = source.read_text(encoding="utf-8")
start = text.index("# BEGIN PROFILE RESOURCES")
end = text.index("# END PROFILE RESOURCES") + len("# END PROFILE RESOURCES")
embedded = ["# Generated by scripts/pack_pipeline.py; edit source/resources, then regenerate.", "import base64", "import zlib"]
for variable, name in (("CORE_TEMPLATE", "core"), ("MATERIAL_TEMPLATE", "frontend-material"), ("VOYAGE_TEMPLATE", "voyage"), ("NEXT_TEMPLATE", "frontend-next"), ("ALL_TEMPLATE", "all"), ("STARTER_TEMPLATE", "app-starter"), ("ANDROID_TEMPLATE", "android"), ("POLICY_TEMPLATE", "mcp-policy"), ("REPOSITORY_POLICY_TEMPLATE", "repository-policy"), ("MARKETING_TEMPLATE", "marketing"), ("HOMEBREW_TEMPLATE", "homebrew-tap"), ("APPLICATION_TEMPLATE", "application-template")):
resource = (source.parent / "templates" / (name + ".json")).read_text(encoding="utf-8").encode("utf-8")
payload = base64.b64encode(zlib.compress(resource, level=9)).decode("ascii")
embedded.append(f'{variable} = json.loads(zlib.decompress(base64.b64decode("{payload}")))')
packed = text[:start] + "\n".join(embedded) + text[end:]
if len(packed.encode("utf-8")) > 100_000:
sys.exit("Packed generator exceeds the tested CircleCI command-argument budget")
if "--check" in sys.argv:
if not output.exists() or output.read_text(encoding="utf-8") != packed:
sys.exit("Packed generator is stale; run python3 scripts/pack_pipeline.py")
else:
output.write_text(packed, encoding="utf-8", newline="\n")