#!/usr/bin/env python3 """Release Arcade-owned games through the Apps package's signed Daochi publisher.""" import argparse import os from pathlib import Path from hashlib import sha256 import json import subprocess import sys ROOT = Path(__file__).resolve().parents[1] if __name__ == '__main__': if '--ssh-target' in sys.argv or any(value.startswith('--ssh-target=') for value in sys.argv): try: receipt = json.loads((ROOT / 'build/compatibility.json').read_text()) component = json.loads((ROOT / 'apps/versions.json').read_text())['node_apps']['chess'] valid = all(receipt.get(key) == component[field] for key, field in [('app_id', 'id'), ('version', 'version'), ('sequence', 'sequence')]) valid = valid and receipt.get('sha256') == sha256((ROOT / 'build/chess/chess.zx').read_bytes()).hexdigest() valid = valid and all(receipt.get(key) is True for key in ['arcade', 'inbe', 'oldest_inbe', 'rules', 'friend_protocol', 'rendering', 'save_restore']) except (OSError, ValueError, KeyError): valid = False if not valid: raise SystemExit('Node publication requires this exact Chess bundle to pass Arcade, intended Inbe and oldest supported Inbe checks') parser = argparse.ArgumentParser(add_help=False) host_source = os.environ.get('INBE_SOURCE') parser.add_argument('--publishers', type=Path, default=Path(host_source) / 'apps/publishers.json' if host_source else None) args, forwarded = parser.parse_known_args() if args.publishers is None and '--help' not in forwarded: parser.error('give --publishers with the intended Inbe publisher pins, or set INBE_SOURCE') publisher_flags = ['--publishers', str(args.publishers)] if args.publishers else [] flags = [] if (ROOT / 'ziran.local.toml').exists() else ['--locked'] def package(name): return Path(subprocess.check_output( [str(ROOT / 'scripts/ziran.sh'), 'pkg', 'path', name, *flags], cwd=ROOT, text=True).strip()) # The publisher retains its signed IDs, release sequence checks and # receiver; released Inbe's pins name the key that may sign node apps. # Source and build outputs belong to Arcade. command = [sys.executable, str(package('apps') / 'scripts/node_release.py'), '--node-app', 'chess', '--app-ledger', str(ROOT / 'apps/versions.json'), '--bundle-directory', str(ROOT / 'build/chess'), *publisher_flags, *forwarded] raise SystemExit(subprocess.run(command, cwd=ROOT).returncode)