diff --git a/.github/workflows/nightly-e2e.yaml b/.github/workflows/nightly-e2e.yaml index 4a3ef528269..d10d1546771 100644 --- a/.github/workflows/nightly-e2e.yaml +++ b/.github/workflows/nightly-e2e.yaml @@ -2550,20 +2550,27 @@ jobs: const since48h = new Date(now.getTime() - 48 * 60 * 60 * 1000).toISOString(); const since24h = new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString(); - const { data } = await github.rest.actions.listWorkflowRuns({ - owner: context.repo.owner, - repo: context.repo.repo, - workflow_id: WORKFLOW_FILE, - created: `>=${since48h}`, - per_page: 50, - }); - - // Find completed scheduled runs from 24–48h ago - const priorRuns = data.workflow_runs.filter(r => - r.status === 'completed' && - r.event === 'schedule' && - new Date(r.created_at) < new Date(since24h) - ); + const priorRuns = []; + for (let page = 1; page <= 10 && priorRuns.length === 0; page++) { + const { data } = await github.rest.actions.listWorkflowRuns({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: WORKFLOW_FILE, + created: `>=${since48h}`, + per_page: 100, + page, + }); + + priorRuns.push( + ...data.workflow_runs.filter(r => + r.status === 'completed' && + r.event === 'schedule' && + new Date(r.created_at) < new Date(since24h) + ) + ); + + if (data.workflow_runs.length < 100) break; + } if (priorRuns.length > 0) { // Check the most recent prior run diff --git a/test/nightly-scorecard.test.ts b/test/nightly-scorecard.test.ts new file mode 100644 index 00000000000..beae3a51568 --- /dev/null +++ b/test/nightly-scorecard.test.ts @@ -0,0 +1,59 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { describe, expect, it } from "vitest"; + +type WorkflowRun = { + status: string; + event: string; + created_at: string; + conclusion: string | null; +}; + +function findPriorScheduledRunFromPages( + pages: WorkflowRun[][], + since24h: string, +): WorkflowRun | undefined { + const priorRuns: WorkflowRun[] = []; + for (let page = 0; page < pages.length && priorRuns.length === 0; page++) { + priorRuns.push( + ...pages[page].filter( + (run) => + run.status === "completed" && + run.event === "schedule" && + new Date(run.created_at) < new Date(since24h), + ), + ); + } + return priorRuns[0]; +} + +describe("nightly scorecard prior-day trend lookup", () => { + it("finds the prior scheduled run even when selective dispatches fill the first API page", () => { + const since24h = "2026-05-19T01:02:21.000Z"; + const firstPage = Array.from({ length: 100 }, (_, index) => ({ + status: "completed", + event: index === 20 ? "schedule" : "workflow_dispatch", + created_at: + index === 20 + ? "2026-05-20T00:21:09Z" + : `2026-05-20T${String(23 - Math.floor(index / 5)).padStart(2, "0")}:00:00Z`, + conclusion: index % 3 === 0 ? "failure" : "success", + })); + const secondPage = [ + { + status: "completed", + event: "schedule", + created_at: "2026-05-19T00:20:30Z", + conclusion: "failure", + }, + ]; + + const result = findPriorScheduledRunFromPages( + [firstPage, secondPage], + since24h, + ); + + expect(result?.created_at).toBe(secondPage[0].created_at); + }); +});