rickub/ci-benchpublic Fork 0
a4751cd6fc45253c96ccddee2df928ab22d7a39a
Commits
Clone
git clone https://git.rickub.com/rickub/ci-bench.git
git clone ssh://git@rickub.com/rickub/ci-bench.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

collect.sh · 60 lines · 1.9 KBBash Blame HistoryRaw
ci-bench: cross-platform CI race scaffold (rickub CI vs GitHub Actions) 0baf736 Olivier Girardot yesterday1#!/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
15set -euo pipefail
16
17usage() {
18 sed -n '2,12p' "$0" >&2
19 exit 2
20}
21
22[ $# -ge 3 ] || usage
23
24platform=$1
25run_id=$2
26shift 2
27
28out="results/$platform/$run_id.json"
29if [ -e "$out" ]; then
30 echo "collect: refusing to overwrite $out (delete it first if intentional)" >&2
31 exit 1
32fi
33
34mkdir -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.
38python3 - "$out" "$@" <<'PY'
39import json, sys
40
41out_path, sources = sys.argv[1], sys.argv[2:]
42records = []
43for 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)
54if not records:
55 sys.exit(f"collect: no records found in {sources}")
56with open(out_path, "w", encoding="utf-8") as fh:
57 json.dump(records, fh, indent=1)
58 fh.write("\n")
59print(f"collect: {len(records)} records -> {out_path}")
60PY