28 lines
1.5 KiB
Python
28 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Run shell suites from a detached worktree, capture every exit."""
|
|
import pathlib, subprocess, json, datetime, sys, os
|
|
root=pathlib.Path.cwd()
|
|
if root == pathlib.Path('/mnt/storage/src/mosaic-stack'):
|
|
raise SystemExit('gate refuses canonical checkout')
|
|
if subprocess.check_output(['git','branch','--show-current'],text=True).strip():
|
|
raise SystemExit('gate requires detached HEAD')
|
|
if os.environ.get('DOCKER_HOST') != 'unix:///nonexistent.sock':
|
|
raise SystemExit('decision 127 requires DOCKER_HOST=unix:///nonexistent.sock')
|
|
out=pathlib.Path(sys.argv[1]); out.mkdir(parents=True,exist_ok=True)
|
|
results=[]
|
|
commands=[]
|
|
for package in [root/'packages/discord']:
|
|
tests=sorted(package.glob('tests/**/*.test.mjs'))
|
|
if tests: commands.append(('node-'+package.name,['node','--test',*[str(t.relative_to(root)) for t in tests]],600))
|
|
for suite in sorted(root.glob('scripts/test-*.sh')):
|
|
commands.append((suite.stem,['bash',str(suite)],600))
|
|
for name,command,timeout in commands:
|
|
began=datetime.datetime.now(datetime.timezone.utc).isoformat()
|
|
with (out/(name+'.txt')).open('w') as log:
|
|
p=subprocess.run(command,cwd=root,stdout=log,stderr=subprocess.STDOUT,timeout=timeout)
|
|
row={'suite':name,'exit':p.returncode,'began':began,'ended':datetime.datetime.now(datetime.timezone.utc).isoformat()}
|
|
results.append(row)
|
|
(out/'gate-results.json').write_text(json.dumps(results,indent=2)+'\n')
|
|
print(json.dumps(row),flush=True)
|
|
sys.exit(any(r['exit'] for r in results))
|