File size: 1,444 Bytes
90a05ec | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import io
import json
import os
import re
import sys
import tarfile
import urllib.request
from pathlib import Path
def main():
manifest = json.loads(Path("upstream.json").read_text())
revision = manifest["commit"]
if not re.fullmatch(r"[0-9a-f]{40}", revision):
raise SystemExit("upstream.json 必须固定完整提交 SHA")
url = f"https://api.github.com/repos/Comfy-Org/ComfyUI/tarball/{revision}"
headers = {"User-Agent": "comfy-space-build"}
if os.environ.get("GITHUB_TOKEN"):
headers["Authorization"] = "Bearer " + os.environ["GITHUB_TOKEN"]
with urllib.request.urlopen(urllib.request.Request(url, headers=headers), timeout=120) as response:
archive_bytes = response.read()
destination = Path(sys.argv[1])
destination.mkdir(parents=True, exist_ok=True)
with tarfile.open(fileobj=io.BytesIO(archive_bytes)) as archive:
for member in archive.getmembers():
parts = Path(member.name).parts[1:]
if not parts:
continue
member.name = str(Path(*parts))
archive.extract(member, destination, filter="data")
code = (destination / "comfyui_version.py").read_text()
if f'"{manifest["version"].removeprefix("v")}"' not in code:
raise SystemExit("提交 SHA 与声明的 ComfyUI 版本不一致")
print("已下载并验证 ComfyUI " + manifest["version"])
if __name__ == "__main__":
main()
|