155 lines
4.8 KiB
Python
155 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Check ZFTurbo upstream releases against local model catalog manifest.
|
|
|
|
Usage:
|
|
python backend/scripts/check_zfturbo_updates.py \
|
|
--manifest backend/model_catalog/upstream_zfturbo_models.yaml \
|
|
--json-out /tmp/zfturbo_updates.json
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
import urllib.request
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import yaml
|
|
|
|
|
|
@dataclass
|
|
class ManifestModel:
|
|
model_id: str
|
|
upstream_tag: str
|
|
weights_url: str
|
|
config_url: str
|
|
status: str
|
|
|
|
|
|
def _github_api_get(url: str) -> Any:
|
|
headers = {
|
|
"Accept": "application/vnd.github+json",
|
|
"User-Agent": "stemengine-zfturbo-check/1.0",
|
|
}
|
|
token = os.environ.get("GITHUB_TOKEN", "").strip()
|
|
if token:
|
|
headers["Authorization"] = f"Bearer {token}"
|
|
|
|
req = urllib.request.Request(url, headers=headers)
|
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
|
return json.loads(resp.read().decode("utf-8"))
|
|
|
|
|
|
def load_manifest(path: Path) -> tuple[str, list[ManifestModel]]:
|
|
raw = yaml.safe_load(path.read_text(encoding="utf-8"))
|
|
source_repo = raw.get("source_repo", "ZFTurbo/Music-Source-Separation-Training")
|
|
models: list[ManifestModel] = []
|
|
for item in raw.get("models", []):
|
|
models.append(
|
|
ManifestModel(
|
|
model_id=item.get("model_id", ""),
|
|
upstream_tag=item.get("upstream_tag", ""),
|
|
weights_url=item.get("weights_url", ""),
|
|
config_url=item.get("config_url", ""),
|
|
status=item.get("status", "unknown"),
|
|
)
|
|
)
|
|
return source_repo, models
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Check ZFTurbo upstream updates")
|
|
parser.add_argument(
|
|
"--manifest",
|
|
default="backend/model_catalog/upstream_zfturbo_models.yaml",
|
|
help="Path to upstream manifest",
|
|
)
|
|
parser.add_argument("--json-out", default="", help="Optional JSON report output path")
|
|
parser.add_argument(
|
|
"--strict",
|
|
action="store_true",
|
|
help="Exit with code 1 when stale or missing-tag models are detected",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
manifest_path = Path(args.manifest)
|
|
if not manifest_path.exists():
|
|
print(f"ERROR: Manifest not found: {manifest_path}", file=sys.stderr)
|
|
return 2
|
|
|
|
source_repo, models = load_manifest(manifest_path)
|
|
|
|
releases = _github_api_get(f"https://api.github.com/repos/{source_repo}/releases?per_page=30")
|
|
release_tags = [r.get("tag_name", "") for r in releases if r.get("tag_name")]
|
|
latest_tag = release_tags[0] if release_tags else ""
|
|
|
|
stale_models: list[dict[str, Any]] = []
|
|
missing_tag_models: list[dict[str, Any]] = []
|
|
|
|
for m in models:
|
|
if not m.upstream_tag or m.upstream_tag == "external":
|
|
continue
|
|
if m.upstream_tag not in release_tags:
|
|
missing_tag_models.append({"model_id": m.model_id, "upstream_tag": m.upstream_tag})
|
|
elif latest_tag and m.upstream_tag != latest_tag:
|
|
stale_models.append(
|
|
{
|
|
"model_id": m.model_id,
|
|
"upstream_tag": m.upstream_tag,
|
|
"latest_tag": latest_tag,
|
|
}
|
|
)
|
|
|
|
report = {
|
|
"source_repo": source_repo,
|
|
"latest_tag": latest_tag,
|
|
"known_release_tags": release_tags,
|
|
"stale_models": stale_models,
|
|
"missing_tag_models": missing_tag_models,
|
|
"model_count": len(models),
|
|
}
|
|
|
|
print(f"# ZFTurbo Upstream Check")
|
|
print(f"- Source repo: {source_repo}")
|
|
print(f"- Latest tag: {latest_tag or 'n/a'}")
|
|
print(f"- Manifest models: {len(models)}")
|
|
|
|
if stale_models:
|
|
print("\n## Models behind latest tag")
|
|
for item in stale_models:
|
|
print(
|
|
f"- {item['model_id']}: pinned {item['upstream_tag']} (latest {item['latest_tag']})"
|
|
)
|
|
else:
|
|
print("\n## Models behind latest tag")
|
|
print("- None")
|
|
|
|
if missing_tag_models:
|
|
print("\n## Models pinned to unknown tags")
|
|
for item in missing_tag_models:
|
|
print(f"- {item['model_id']}: missing tag {item['upstream_tag']}")
|
|
|
|
if args.json_out:
|
|
out_path = Path(args.json_out)
|
|
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
out_path.write_text(json.dumps(report, indent=2), encoding="utf-8")
|
|
print(f"\nWrote JSON report: {out_path}")
|
|
|
|
if args.strict and (stale_models or missing_tag_models):
|
|
print(
|
|
"\nSTRICT CHECK FAILED: upstream drift detected. "
|
|
"Review manifest pins and update model entries before marking in-sync.",
|
|
file=sys.stderr,
|
|
)
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|