Headless 3D and VFX engine for agents. Research preview.
#!/usr/bin/env python3
"""Select an unexpired private distribution artifact matching this checkout's version.
Uses read-only GitHub API calls through gh. Never changes a version or repository.
"""
import argparse
import base64
import json
import os
from pathlib import Path
import subprocess
import tomllib
p = argparse.ArgumentParser(description=__doc__)
p.add_argument('--workflow', required=True)
p.add_argument('--platform', required=True)
p.add_argument('--run')
a = p.parse_args()
repo = os.environ.get('GITHUB_REPOSITORY', 'voyager-so/vork')
version = tomllib.loads((Path(__file__).resolve().parents[1] / 'Cargo.toml').read_text())['workspace']['package']['version']
def api(path):
return json.loads(subprocess.check_output(['gh', 'api', f'repos/{repo}/{path}'], text=True))
runs = [api(f'actions/runs/{a.run}')] if a.run else api(f'actions/workflows/{a.workflow}/runs?status=success&per_page=100')['workflow_runs']
versions = {}
for run in runs:
if run['conclusion'] != 'success' or Path(run['path']).name != a.workflow:
continue
sha = run['head_sha']
if sha not in versions:
content = api(f'contents/Cargo.toml?ref={sha}')['content']
versions[sha] = tomllib.loads(base64.b64decode(content).decode())['workspace']['package']['version']
if versions[sha] != version:
continue
artifacts = api(f'actions/runs/{run["id"]}/artifacts?per_page=100')['artifacts']
if any(item['name'] == a.platform and not item['expired'] for item in artifacts):
print(run['id'])
break
else:
p.error(f'no successful {a.workflow} artifact for {a.platform} with source version {version}; build/sign matching artifacts or supply --run')