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
9 changes: 7 additions & 2 deletions dist/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 24 additions & 8 deletions src/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand All @@ -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]"
`,
);
Expand All @@ -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}`,
);

Expand Down Expand Up @@ -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);
Expand All @@ -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: []"
`,
);
Expand All @@ -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
Expand All @@ -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: []"
`,
);
Expand All @@ -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
Expand All @@ -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: []"
`,
);
Expand All @@ -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
Expand All @@ -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: []"
`,
);
Expand Down
6 changes: 6 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,23 @@ export async function fetchWorkflowRunUrl(runId: number): Promise<string> {
export async function fetchWorkflowRunIds(
workflowId: number,
branch: BranchNameResult,
startTimeISO: string,
): Promise<number[]> {
try {
const useBranchFilter =
!branch.isTag &&
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,
Expand Down Expand Up @@ -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(", ")}]`,
);

Expand Down
3 changes: 2 additions & 1 deletion src/return-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export async function getRunIdAndUrl({
workflowTimeoutMs,
workflowJobStepsRetryMs,
}: GetRunIdAndUrlOpts): Promise<Result<{ id: number; url: string }>> {
const startTimeISO = new Date(startTime).toISOString();
const retryTimeout = Math.max(
constants.WORKFLOW_FETCH_TIMEOUT_MS,
workflowTimeoutMs,
Expand All @@ -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) {
Expand Down
Loading