Skip to content

Commit 394811d

Browse files
committed
feat: improve workflow filtering by adding created filter
1 parent 4c2dbf2 commit 394811d

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

dist/index.mjs

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ describe("API", () => {
370370
"Fetched Workflow Runs:
371371
Repository: owner/repository
372372
Branch Filter: true (feature_branch)
373+
Created Filter:
373374
Workflow ID: 0
374375
Runs Fetched: [0, 1, 2]"
375376
`,
@@ -427,6 +428,7 @@ describe("API", () => {
427428
"Fetched Workflow Runs:
428429
Repository: owner/repository
429430
Branch Filter: true (feature_branch)
431+
Created Filter:
430432
Workflow ID: 0
431433
Runs Fetched: []"
432434
`,
@@ -464,6 +466,7 @@ describe("API", () => {
464466
"Fetched Workflow Runs:
465467
Repository: owner/repository
466468
Branch Filter: true (master)
469+
Created Filter:
467470
Workflow ID: 0
468471
Runs Fetched: []"
469472
`,
@@ -501,6 +504,7 @@ describe("API", () => {
501504
"Fetched Workflow Runs:
502505
Repository: owner/repository
503506
Branch Filter: false (/refs/tags/1.5.0)
507+
Created Filter:
504508
Workflow ID: 0
505509
Runs Fetched: []"
506510
`,
@@ -538,6 +542,7 @@ describe("API", () => {
538542
"Fetched Workflow Runs:
539543
Repository: owner/repository
540544
Branch Filter: false (/refs/cake)
545+
Created Filter:
541546
Workflow ID: 0
542547
Runs Fetched: []"
543548
`,

src/api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export async function fetchWorkflowRunUrl(runId: number): Promise<string> {
158158
export async function fetchWorkflowRunIds(
159159
workflowId: number,
160160
branch: BranchNameResult,
161+
created: Date | undefined = undefined,
161162
): Promise<number[]> {
162163
try {
163164
const useBranchFilter =
@@ -170,6 +171,7 @@ export async function fetchWorkflowRunIds(
170171
owner: config.owner,
171172
repo: config.repo,
172173
workflow_id: workflowId,
174+
...(created ? {created: `>=${created.toISOString()}`} : {}),
173175
...(useBranchFilter
174176
? {
175177
branch: branch.branchName,
@@ -198,6 +200,7 @@ export async function fetchWorkflowRunIds(
198200
"Fetched Workflow Runs:\n" +
199201
` Repository: ${config.owner}/${config.repo}\n` +
200202
` Branch Filter: ${branchMsg}\n` +
203+
` Created Filter: ${created?.toISOString() ?? ""}\n` +
201204
` Workflow ID: ${workflowId}\n` +
202205
` Runs Fetched: [${runIds.join(", ")}]`,
203206
);

src/main.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe("main", () => {
169169
// Get run ID
170170
expect(returnDispatchGetRunIdAndUrlMock).toHaveBeenCalledOnce();
171171
expect(returnDispatchGetRunIdAndUrlMock).toHaveBeenCalledWith({
172-
startTime: Date.now(),
172+
startTime: new Date(),
173173
branch: testBranch,
174174
distinctIdRegex: distinctIdRegex,
175175
workflowId: 0,

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
export async function main(): Promise<void> {
1818
try {
19-
const startTime = Date.now();
19+
const startTime = new Date();
2020

2121
const config = getConfig();
2222
api.init(config);
@@ -48,10 +48,10 @@ export async function main(): Promise<void> {
4848
});
4949
if (result.success) {
5050
handleActionSuccess(result.value.id, result.value.url);
51-
core.debug(`Completed (${Date.now() - startTime}ms)`);
51+
core.debug(`Completed (${Date.now() - startTime.getTime()}ms)`);
5252
} else {
5353
handleActionFail();
54-
core.debug(`Timed out (${Date.now() - startTime}ms)`);
54+
core.debug(`Timed out (${Date.now() - startTime.getTime()}ms)`);
5555
}
5656
} catch (error) {
5757
if (error instanceof Error) {

src/return-dispatch.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ describe("return-dispatch", () => {
475475
branchName: "main",
476476
});
477477
const defaultOpts: GetRunIdAndUrlOpts = {
478-
startTime: Date.now(),
478+
startTime: new Date(),
479479
branch: branch,
480480
distinctIdRegex: distinctIdRegex,
481481
workflowId: workflowId,
@@ -837,7 +837,7 @@ describe("return-dispatch", () => {
837837
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
838838

839839
expect(utilSleepMock).toHaveBeenCalledTimes(3);
840-
const elapsedTime = Date.now() - defaultOpts.startTime; // `waitTime` should be using `workflowTimeoutMs` at this point
840+
const elapsedTime = Date.now() - defaultOpts.startTime.getTime(); // `waitTime` should be using `workflowTimeoutMs` at this point
841841
expect(utilSleepMock.mock.lastCall?.[0]).approximately(
842842
timeoutMs - elapsedTime,
843843
5,

src/return-dispatch.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function handleActionFail(): void {
124124
}
125125

126126
export interface GetRunIdAndUrlOpts {
127-
startTime: number;
127+
startTime: Date;
128128
branch: BranchNameResult;
129129
distinctIdRegex: RegExp;
130130
workflowId: number;
@@ -145,18 +145,18 @@ export async function getRunIdAndUrl({
145145
);
146146

147147
let attemptNo = 0;
148-
let elapsedTime = Date.now() - startTime;
148+
let elapsedTime = Date.now() - startTime.getTime();
149149
while (elapsedTime < workflowTimeoutMs) {
150150
attemptNo++;
151151

152152
// Get all runs for a given workflow ID
153153
const fetchWorkflowRunIds = await api.retryOrTimeout(
154-
() => api.fetchWorkflowRunIds(workflowId, branch),
154+
() => api.fetchWorkflowRunIds(workflowId, branch, startTime),
155155
retryTimeout,
156156
);
157157
if (!fetchWorkflowRunIds.success) {
158158
core.debug(
159-
`Timed out while attempting to fetch Workflow Run IDs, waited ${Date.now() - startTime}ms`,
159+
`Timed out while attempting to fetch Workflow Run IDs, waited ${Date.now() - startTime.getTime()}ms`,
160160
);
161161
break;
162162
}
@@ -188,7 +188,7 @@ export async function getRunIdAndUrl({
188188
core.info(`Waiting for ${waitTime}ms before the next attempt...`);
189189
await sleep(waitTime);
190190

191-
elapsedTime = Date.now() - startTime;
191+
elapsedTime = Date.now() - startTime.getTime();
192192
}
193193

194194
return { success: false, reason: "timeout" };

0 commit comments

Comments
 (0)