ci: Capture actual task durations under turbo 2.x summary schema (#30908)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Declan Carroll 2026-05-22 07:50:49 +01:00 committed by GitHub
parent d82fbc8f85
commit 700243f5db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,10 +37,16 @@ const summary = JSON.parse(readFileSync(join(runsDir, files.at(-1)), 'utf-8'));
const metrics = [];
// turbo 2.x emits start/end timestamps rather than a `durationMs` field.
// For cache hits, the execution window measures only restore overhead (~ms),
// so we use `cache.timeSaved` — the duration of the run we avoided — instead.
const elapsedMs = ({ startTime, endTime } = {}) =>
startTime && endTime ? endTime - startTime : 0;
for (const task of summary.tasks ?? []) {
if (task.execution?.exitCode !== 0) continue;
const durationMs = task.execution.durationMs ?? 0;
const cacheHit = task.cache?.status === 'HIT';
const durationMs = cacheHit ? (task.cache.timeSaved ?? 0) : elapsedMs(task.execution);
// taskId format: "package-name#task-name"
const [pkg, taskName] = task.taskId?.split('#') ?? [task.package, task.task];
@ -53,7 +59,7 @@ for (const task of summary.tasks ?? []) {
);
}
const totalMs = summary.durationMs ?? 0;
const totalMs = elapsedMs(summary.execution);
const totalTasks = summary.tasks?.length ?? 0;
const cachedTasks = summary.tasks?.filter((t) => t.cache?.status === 'HIT').length ?? 0;