#!/usr/bin/env python3 """Upload the exact verified package recorded by an existing release tag.""" import argparse import json from pathlib import Path import subprocess ROOT = Path(__file__).resolve().parent.parent def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--tag", required=True) parser.add_argument("--notes", required=True, type=Path) parser.add_argument("--pkg-forge-repo", type=Path, default=Path.home() / "Documents/dayu-git/repositories/pkg-forge") args = parser.parse_args() report = json.loads((ROOT / "verification/Package.json").read_text()) assert report["pass"] and not report["testUnsigned"] and report["notarization"]["status"] == "Accepted" tag_report = json.loads(subprocess.check_output( ["git", "show", args.tag + ":verification/Package.json"], cwd=ROOT, text=True)) for key in ["sha256", "bytes", "appCompiledSource", "appBuild"]: assert tag_report[key] == report[key], "所选标签与当前已验包记录不一致:" + key app = report["resources"][0] assert app["bundleID"] == "com.dayu.color" and app["version"] == tag_report["resources"][0]["version"] package = Path(report["package"]) signature = subprocess.check_output(["pkgutil", "--check-signature", str(package)], text=True) assert "Developer ID Installer: zhong luo (B3W25FX5H5)" in signature subprocess.run(["xcrun", "stapler", "validate", str(package)], check=True, capture_output=True) subprocess.run(["spctl", "--assess", "--type", "install", str(package)], check=True, capture_output=True) commit = subprocess.check_output(["git", "rev-parse", args.tag + "^{commit}"], cwd=ROOT, text=True).strip() helper = args.pkg_forge_repo / "skills/pkg-forge/scripts/publish_release.py" result = subprocess.run(["python3", str(helper), "--repository", "dayu/dayu-color", "--repo-root", str(ROOT), "--tag", args.tag, "--commit", commit, "--title", "大鱼调色 " + app["version"] + "(" + app["build"] + ")", "--body-file", str(args.notes.resolve()), "--asset", str(package), "--sha256", report["sha256"], "--bytes", str(report["bytes"]), "--account", "dayu", "--report", str(ROOT / "verification/Release.json")]) return result.returncode if __name__ == "__main__": raise SystemExit(main())