diff --git a/dist/index.mjs b/dist/index.mjs index 429f5942..260b76af 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -24129,13 +24129,16 @@ async function fetchWorkflowRunUrl(runId) { throw error5; } } -async function fetchWorkflowRunIds(workflowId, branch) { +async function fetchWorkflowRunIds(workflowId, branch, startTimeISO) { try { const useBranchFilter = !branch.isTag && branch.branchName !== void 0 && branch.branchName !== ""; + const createdFrom = `>=${startTimeISO}`; const response = await octokit.rest.actions.listWorkflowRuns({ owner: config.owner, repo: config.repo, workflow_id: workflowId, + created: createdFrom, + event: "workflow_dispatch", ...useBranchFilter ? { branch: branch.branchName, per_page: 10 @@ -24157,6 +24160,7 @@ async function fetchWorkflowRunIds(workflowId, branch) { Repository: ${config.owner}/${config.repo} Branch Filter: ${branchMsg} Workflow ID: ${workflowId} + Created: ${createdFrom} Runs Fetched: [${runIds.join(", ")}]` ); return runIds; @@ -24321,6 +24325,7 @@ async function getRunIdAndUrl({ workflowTimeoutMs, workflowJobStepsRetryMs }) { + const startTimeISO = new Date(startTime).toISOString(); const retryTimeout = Math.max( WORKFLOW_FETCH_TIMEOUT_MS, workflowTimeoutMs @@ -24330,7 +24335,7 @@ async function getRunIdAndUrl({ while (elapsedTime < workflowTimeoutMs) { attemptNo++; const fetchWorkflowRunIds2 = await retryOrTimeout( - () => fetchWorkflowRunIds(workflowId, branch), + () => fetchWorkflowRunIds(workflowId, branch, startTimeISO), retryTimeout ); if (!fetchWorkflowRunIds2.success) { diff --git a/src/api.spec.ts b/src/api.spec.ts index 6723b322..135c3b67 100644 --- a/src/api.spec.ts +++ b/src/api.spec.ts @@ -326,6 +326,7 @@ describe("API", () => { }); describe("fetchWorkflowRunIds", () => { + const startTimeISO = "2025-06-17T22:24:23.238Z"; const workflowIdCfg: ActionConfig = { token: "secret", ref: "/refs/heads/feature_branch", @@ -358,9 +359,9 @@ describe("API", () => { ); // Behaviour - await expect(fetchWorkflowRunIds(0, branch)).resolves.toStrictEqual( - mockData.workflow_runs.map((run) => run.id), - ); + await expect( + fetchWorkflowRunIds(0, branch, startTimeISO), + ).resolves.toStrictEqual(mockData.workflow_runs.map((run) => run.id)); // Logging assertOnlyCalled(coreDebugLogMock); @@ -371,6 +372,7 @@ describe("API", () => { Repository: owner/repository Branch Filter: true (feature_branch) Workflow ID: 0 + Created: >=2025-06-17T22:24:23.238Z Runs Fetched: [0, 1, 2]" `, ); @@ -389,7 +391,9 @@ describe("API", () => { ); // Behaviour - await expect(fetchWorkflowRunIds(0, branch)).rejects.toThrow( + await expect( + fetchWorkflowRunIds(0, branch, startTimeISO), + ).rejects.toThrow( `Failed to fetch Workflow runs, expected 200 but received ${errorStatus}`, ); @@ -417,7 +421,9 @@ describe("API", () => { ); // Behaviour - await expect(fetchWorkflowRunIds(0, branch)).resolves.toStrictEqual([]); + await expect( + fetchWorkflowRunIds(0, branch, startTimeISO), + ).resolves.toStrictEqual([]); // Logging assertOnlyCalled(coreDebugLogMock); @@ -428,6 +434,7 @@ describe("API", () => { Repository: owner/repository Branch Filter: true (feature_branch) Workflow ID: 0 + Created: >=2025-06-17T22:24:23.238Z Runs Fetched: []" `, ); @@ -453,7 +460,9 @@ describe("API", () => { ); // Behaviour - await expect(fetchWorkflowRunIds(0, branch)).resolves.not.toThrow(); + await expect( + fetchWorkflowRunIds(0, branch, startTimeISO), + ).resolves.not.toThrow(); expect(parsedRef).toStrictEqual("master"); // Logging @@ -465,6 +474,7 @@ describe("API", () => { Repository: owner/repository Branch Filter: true (master) Workflow ID: 0 + Created: >=2025-06-17T22:24:23.238Z Runs Fetched: []" `, ); @@ -490,7 +500,9 @@ describe("API", () => { ); // Behaviour - await expect(fetchWorkflowRunIds(0, branch)).resolves.not.toThrow(); + await expect( + fetchWorkflowRunIds(0, branch, startTimeISO), + ).resolves.not.toThrow(); expect(parsedRef).toBeUndefined(); // Logging @@ -502,6 +514,7 @@ describe("API", () => { Repository: owner/repository Branch Filter: false (/refs/tags/1.5.0) Workflow ID: 0 + Created: >=2025-06-17T22:24:23.238Z Runs Fetched: []" `, ); @@ -527,7 +540,9 @@ describe("API", () => { ); // Behaviour - await expect(fetchWorkflowRunIds(0, branch)).resolves.not.toThrow(); + await expect( + fetchWorkflowRunIds(0, branch, startTimeISO), + ).resolves.not.toThrow(); expect(parsedRef).toBeUndefined(); // Logging @@ -539,6 +554,7 @@ describe("API", () => { Repository: owner/repository Branch Filter: false (/refs/cake) Workflow ID: 0 + Created: >=2025-06-17T22:24:23.238Z Runs Fetched: []" `, ); diff --git a/src/api.ts b/src/api.ts index 2c0a07e2..e88d5767 100644 --- a/src/api.ts +++ b/src/api.ts @@ -158,6 +158,7 @@ export async function fetchWorkflowRunUrl(runId: number): Promise { export async function fetchWorkflowRunIds( workflowId: number, branch: BranchNameResult, + startTimeISO: string, ): Promise { try { const useBranchFilter = @@ -165,11 +166,15 @@ export async function fetchWorkflowRunIds( branch.branchName !== undefined && branch.branchName !== ""; + const createdFrom = `>=${startTimeISO}`; + // https://docs.github.com/en/rest/actions/workflow-runs#list-workflow-runs-for-a-repository const response = await octokit.rest.actions.listWorkflowRuns({ owner: config.owner, repo: config.repo, workflow_id: workflowId, + created: createdFrom, + event: "workflow_dispatch", ...(useBranchFilter ? { branch: branch.branchName, @@ -199,6 +204,7 @@ export async function fetchWorkflowRunIds( ` Repository: ${config.owner}/${config.repo}\n` + ` Branch Filter: ${branchMsg}\n` + ` Workflow ID: ${workflowId}\n` + + ` Created: ${createdFrom}\n` + ` Runs Fetched: [${runIds.join(", ")}]`, ); diff --git a/src/return-dispatch.ts b/src/return-dispatch.ts index a7d17836..c5819587 100644 --- a/src/return-dispatch.ts +++ b/src/return-dispatch.ts @@ -139,6 +139,7 @@ export async function getRunIdAndUrl({ workflowTimeoutMs, workflowJobStepsRetryMs, }: GetRunIdAndUrlOpts): Promise> { + const startTimeISO = new Date(startTime).toISOString(); const retryTimeout = Math.max( constants.WORKFLOW_FETCH_TIMEOUT_MS, workflowTimeoutMs, @@ -151,7 +152,7 @@ export async function getRunIdAndUrl({ // Get all runs for a given workflow ID const fetchWorkflowRunIds = await api.retryOrTimeout( - () => api.fetchWorkflowRunIds(workflowId, branch), + () => api.fetchWorkflowRunIds(workflowId, branch, startTimeISO), retryTimeout, ); if (!fetchWorkflowRunIds.success) {