| ci-bench: cross-platform CI race scaffold (rickub CI vs GitHub Actions) 0baf736 Olivier Girardot yesterday | 1 | #!/usr/bin/env bash |
| 2 | # collect.sh — gather one run's results.jsonl into the results tree. |
| 3 | # |
| 4 | # scripts/collect.sh PLATFORM RUN_ID SRC [SRC...] |
| 5 | # |
| 6 | # PLATFORM github | rickub | local |
| 7 | # RUN_ID the run's identifier (bench run_id / artifact run number) |
| 8 | # SRC one or more results.jsonl files (e.g. a downloaded artifact, |
| 9 | # extracted anywhere; multiple are concatenated in order) |
| 10 | # |
| 11 | # Output: results/<platform>/<run-id>.json — a JSON array of the run's records, |
| 12 | # normalized (blank lines dropped). Refuses to overwrite an existing file: two |
| 13 | # collected runs with the same id are almost certainly a copy/paste mistake. |
| 14 | |
| 15 | set -euo pipefail |
| 16 | |
| 17 | usage() { |
| 18 | sed -n '2,12p' "$0" >&2 |
| 19 | exit 2 |
| 20 | } |
| 21 | |
| 22 | [ $# -ge 3 ] || usage |
| 23 | |
| 24 | platform=$1 |
| 25 | run_id=$2 |
| 26 | shift 2 |
| 27 | |
| 28 | out="results/$platform/$run_id.json" |
| 29 | if [ -e "$out" ]; then |
| 30 | echo "collect: refusing to overwrite $out (delete it first if intentional)" >&2 |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | mkdir -p "results/$platform" |
| 35 | |
| 36 | # Concatenate the sources, drop blanks, and re-emit as a JSON array via |
| 37 | # python3 (stdlib) so the output is valid JSON even from partial files. |
| 38 | python3 - "$out" "$@" <<'PY' |
| 39 | import json, sys |
| 40 | |
| 41 | out_path, sources = sys.argv[1], sys.argv[2:] |
| 42 | records = [] |
| 43 | for src in sources: |
| 44 | with open(src, "r", encoding="utf-8", errors="replace") as fh: |
| 45 | for line in fh: |
| 46 | line = line.strip() |
| 47 | if not line: |
| 48 | continue |
| 49 | try: |
| 50 | records.append(json.loads(line)) |
| 51 | except json.JSONDecodeError: |
| 52 | # A torn last line (job killed mid-write): keep it out but say so. |
| 53 | print(f"collect: skipping unparseable line in {src}: {line[:80]!r}", file=sys.stderr) |
| 54 | if not records: |
| 55 | sys.exit(f"collect: no records found in {sources}") |
| 56 | with open(out_path, "w", encoding="utf-8") as fh: |
| 57 | json.dump(records, fh, indent=1) |
| 58 | fh.write("\n") |
| 59 | print(f"collect: {len(records)} records -> {out_path}") |
| 60 | PY |