Files
solvecraft/scripts/fetch-reports.sh
T
bherbruck ead02a9ec1 ci: cut CI wall time (parallel jobs, opt-level 0 difftest glue, time-ordered queue)
- difftest no longer waits for the test job; cpp clippy moves to the clippy job and
  the runner tests to the test job (both 8 vCPU), sharing a composite action that
  clones upstream, enables sccache and installs the C++ reference.
- [profile.difftest.package.difftest] opt-level = 0: the ~300k-line runner crate took
  ~5 of the ~6 build minutes at opt-level 3; solidcore stays at 3. Reports are
  byte-identical.
- difftest --jobs orders its queue by each unit's wall time in the previous run
  (reports/difftest/times.tsv, uploaded with main's reports), so the slowest unit
  starts first and the run ends at the longest unit's time.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0158BfaB2oaoX64fskuKP1bm
2026-10-22 00:55:52 -04:00

69 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Fetches the difftest reports (reports/difftest/<unit>.json) of main's latest CI run.
#
# Reports are not committed: the CI difftest job on every push to main uploads them as
# the artifact `difftest-reports`. This downloads the newest one, taken only from a push
# run of this repo's own .github/workflows/ci.yml on main, into reports/difftest/
# (replacing its *.json). Needs `gh` with read access to Actions (GH_TOKEN in CI).
# When no artifact is available (none uploaded yet, or expired) it falls back to the
# last committed set in git history (needs a non-shallow clone), and exits 1 if that
# fails too. Running difftest locally regenerates the reports of the units you run.
#
# scripts/fetch-reports.sh [DEST] # DEST defaults to reports/difftest
set -euo pipefail
root=$(git rev-parse --show-toplevel)
dest=${1:-$root/reports/difftest}
repo=${GITHUB_REPOSITORY:-tangency-labs/solidcore}
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
install() {
local src=$1 n
n=$(find "$src" -maxdepth 1 -name '*.json' | wc -l)
[ "$n" -gt 0 ] || return 1
mkdir -p "$dest"
find "$dest" -maxdepth 1 -name '*.json' -delete
find "$src" -maxdepth 1 -name '*.json' -exec mv -t "$dest" {} +
# Per-unit wall times of that run (difftest --jobs queue order only).
if [ -f "$src/times.tsv" ]; then mv "$src/times.tsv" "$dest/"; fi
echo "fetch-reports: $n reports -> ${dest#"$root"/} ($2)"
}
if command -v gh >/dev/null; then
# Trust only push runs of this repo's own .github/workflows/ci.yml on main. Never
# select by branch name alone: a fork PR can name its branch "main" too.
runs=$(gh api "repos/$repo/actions/workflows/ci.yml/runs?branch=main&event=push&per_page=20" \
-q ".workflow_runs[]
| select(.event == \"push\" and .path == \".github/workflows/ci.yml\"
and .head_branch == \"main\"
and .repository.full_name == \"$repo\"
and .head_repository.full_name == \"$repo\")
| .id" 2>/dev/null | head -n 10 || true)
for id in $runs; do
art=$(gh api "repos/$repo/actions/runs/$id/artifacts?name=difftest-reports" \
-q '.artifacts[] | select(.expired | not) | .id' 2>/dev/null | head -n 1 || true)
[ -n "$art" ] || continue
if gh run download "$id" -R "$repo" -n difftest-reports -D "$tmp/run" >/dev/null 2>&1 \
&& install "$tmp/run" "CI run $id"; then
exit 0
fi
rm -rf "$tmp/run"
done
echo "fetch-reports: no difftest-reports artifact from main's CI" >&2
fi
# Fallback: the set committed before reports moved to CI artifacts.
last=$(git -C "$root" rev-list -1 HEAD -- reports/difftest 2>/dev/null || true)
if [ -n "$last" ]; then
for c in "$last" "$last^"; do
if git -C "$root" cat-file -e "$c:reports/difftest" 2>/dev/null; then
mkdir -p "$tmp/git"
git -C "$root" archive "$c" reports/difftest | tar -x -C "$tmp/git"
install "$tmp/git/reports/difftest" "committed in ${c}" && exit 0
fi
done
fi
echo "fetch-reports: no reports found" >&2
exit 1