clone

a personal forge on plain git: static pages, stacked-diff reviews, signed local ci, repo sites and releases

main
forge / test / scenarios / lake-ci-metrics.sh
lake-ci-metrics.sh 2.4K
1# Metrics: .forge/ci writes "name number [unit]" lines to $FORGE_METRICS,2# forge attest signs them into the statement, and the lake keeps a row a3# metric in ci_metrics. A repo's insights.json charts each one by commit on4# its default branch, matched by tree, so a commit reworded after it was5# attested keeps its values.6. "$(dirname "$0")/../lib.sh"7user dami8repo dami/greet9clone dami dami/greet "$T/w/d"10mkdir -p "$T/w/d/.forge"11cat >"$T/w/d/.forge/ci" <<'EOF'12#!/bin/sh13n=$(git rev-list --count HEAD)14{15 echo "files $n"16 echo "bundle_kb 41.5 KB"17 echo "Not A Metric"18 echo "files 9"19} >"$FORGE_METRICS"20EOF21chmod +x "$T/w/d/.forge/ci"22at "$T/w/d" commit "ci reports metrics"23ok at "$T/w/d" "$FORGE" attest24has "$T_LOG" 'FORGE_METRICS: line 3 is not "name number \[unit\]"; left out'25has "$T_LOG" 'FORGE_METRICS: files twice; the first is kept'26note=$(git -C "$T/w/d" notes --ref=ci show HEAD)27case $note in *"metric files 128metric bundle_kb 41.5 KB29log sha256:"*) ;; *) fail "the statement lacks its metric lines: $note" ;; esac30# Reworded after the attestation: same tree, another commit.31git -C "$T/w/d" commit -q --amend -m "ci reports metrics, reworded"32ok push_as dami "$T/w/d" origin main refs/notes/ci33ok forge lake34eq "$(lq "SELECT string_agg(name || '=' || value || coalesce(unit, ''), ';' ORDER BY name) FROM ci_metrics")" 'bundle_kb=41.5KB;files=1.0'35eq "$(lq "SELECT count(*) FROM ci_metrics m JOIN ci USING (id) WHERE ci.verified AND m.tree = ci.tree")" 236eq "$(lq "SELECT count(*) FROM commits WHERE tree IS NOT NULL")" 137# A second commit: the chart has two points.38at "$T/w/d" commit "another file"39ok at "$T/w/d" "$FORGE" attest40ok push_as dami "$T/w/d" origin main refs/notes/ci41build dami/greet42ok forge lake43j=$FORGE_WWW/dami/greet/insights/insights.json44has "$j" '"metrics":\[\["bundle_kb","KB",\[\[[0-9]+,41.5,"[0-9a-f]{40}","[a-z ,]+"\],\[[0-9]+,41.5,'45has "$j" '\["files",null,\[(\[[0-9]+,[12],"[0-9a-f]{40}","[a-z ,]+"\],?){2}\]\]'46has "$j" '\[[0-9]+,1,"[0-9a-f]{40}","ci reports metrics, reworded"\]'47has "$j" '\[[0-9]+,2,"[0-9a-f]{40}","another file"\]'48[ "$(head -c 4 "$FORGE_WWW/dami/greet/insights/ci_metrics.parquet")" = PAR1 ] || fail "ci_metrics.parquet isn't Parquet"49# The forge's insights have no metrics chart: names mean something per repo.50lacks "$FORGE_WWW/insights/insights.json" '"metrics"'51has "$FORGE_WWW/dami/greet/insights/index.html" 'id="ins-metrics" hidden'