Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions .github/workflows/nightly-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 59 additions & 0 deletions test/nightly-scorecard.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading