diff --git a/tools/updater-lifecycle-3.4.mjs b/tools/updater-lifecycle-3.4.mjs index 8cca9f3..8291b4b 100644 --- a/tools/updater-lifecycle-3.4.mjs +++ b/tools/updater-lifecycle-3.4.mjs @@ -129,9 +129,12 @@ function normalizeRun(run) { } function bestRun(runs) { - const successful = runs.filter(run => run.state === 'success').sort((a, b) => time(b.updatedAt) - time(a.updatedAt))[0]; - if (successful) return successful; - return [...runs].sort((a, b) => time(b.updatedAt) - time(a.updatedAt))[0]; + return [...runs].sort((a, b) => { + const dateDelta = time(b.updatedAt) - time(a.updatedAt); + if (dateDelta) return dateDelta; + const rank = { success: 4, pending: 3, failure: 2, cancelled: 1, missing: 0 }; + return (rank[b.state] || 0) - (rank[a.state] || 0); + })[0]; } export function classifyChecks({ checks = [], workflowRuns = [], requiredChecks = REQUIRED_CHECKS, requiredWorkflows = REQUIRED_WORKFLOWS, elapsedSeconds = 0, gracePeriodSeconds = 90, timedOut = false }) {