diff --git a/.github/scripts/send-build-stats.mjs b/.github/scripts/send-build-stats.mjs index 4a7a06dc815..23dde7472d2 100644 --- a/.github/scripts/send-build-stats.mjs +++ b/.github/scripts/send-build-stats.mjs @@ -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;