Skip to content

Commit 3a03473

Browse files
committed
refactor: lift extra logging to main
1 parent d2aecb4 commit 3a03473

File tree

5 files changed

+38
-87
lines changed

5 files changed

+38
-87
lines changed
Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,27 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`return-dispatch > handleAction > getRunIdAndUrl > called fetchWorkflowRunIds with the provided workflowId and branch 1`] = `"Attempting to identify run ID for workflow.yml (123)"`;
3+
exports[`return-dispatch > handleAction > getRunIdAndUrl > called fetchWorkflowRunIds with the provided workflowId and branch 1`] = `"Attempting to get step names for Run IDs: [0]"`;
44

5-
exports[`return-dispatch > handleAction > getRunIdAndUrl > called fetchWorkflowRunIds with the provided workflowId and branch 2`] = `"Attempting to get step names for Run IDs: [0]"`;
5+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should call retryOrTimeout with the larger workflowTimeoutMs timeout value 1`] = `"Attempting to get step names for Run IDs: [0]"`;
66

7-
exports[`return-dispatch > handleAction > getRunIdAndUrl > called fetchWorkflowRunIds with the provided workflowId and branch 3`] = `"Attempting to identify run ID from steps..."`;
7+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should retry until an ID is found 1`] = `"No Run IDs found for workflow, attempt 1..."`;
88

9-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should call retryOrTimeout with the larger workflowTimeoutMs timeout value 1`] = `"Attempting to identify run ID for workflow.yml (123)"`;
9+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should retry until an ID is found 2`] = `"No Run IDs found for workflow, attempt 2..."`;
1010

11-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should call retryOrTimeout with the larger workflowTimeoutMs timeout value 2`] = `"Attempting to get step names for Run IDs: [0]"`;
11+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should retry until an ID is found 3`] = `"Attempting to get step names for Run IDs: [0]"`;
1212

13-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should call retryOrTimeout with the larger workflowTimeoutMs timeout value 3`] = `"Attempting to identify run ID from steps..."`;
13+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should return the ID when found 1`] = `"Attempting to get step names for Run IDs: [0]"`;
1414

15-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should retry until an ID is found 1`] = `"Attempting to identify run ID from steps..."`;
15+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should return the ID when found 2`] = `undefined`;
1616

17-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should retry until an ID is found 2`] = `"No Run IDs found for workflow, attempt 1..."`;
17+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 1`] = `"Exhausted searching IDs in known runs, attempt 1..."`;
1818

19-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should retry until an ID is found 3`] = `"Attempting to identify run ID for workflow.yml (123)"`;
19+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 2`] = `"Attempting to get step names for Run IDs: [0]"`;
2020

21-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should retry until an ID is found 4`] = `"No Run IDs found for workflow, attempt 2..."`;
22-
23-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should retry until an ID is found 5`] = `"Attempting to get step names for Run IDs: [0]"`;
24-
25-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should return the ID when found 1`] = `"Attempting to identify run ID for workflow.yml (123)"`;
26-
27-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should return the ID when found 2`] = `"Attempting to get step names for Run IDs: [0]"`;
28-
29-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should return the ID when found 3`] = `"Attempting to identify run ID from steps..."`;
30-
31-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable failing to get the run IDs 1`] = `"Attempting to identify run ID for workflow.yml (123)"`;
32-
33-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable failing to get the run IDs 2`] = `"Attempting to identify run ID from steps..."`;
34-
35-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 1`] = `"Attempting to identify run ID from steps..."`;
36-
37-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 2`] = `"Exhausted searching IDs in known runs, attempt 1..."`;
38-
39-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 3`] = `"Attempting to identify run ID for workflow.yml (123)"`;
21+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 3`] = `"Exhausted searching IDs in known runs, attempt 2..."`;
4022

4123
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 4`] = `"Attempting to get step names for Run IDs: [0]"`;
4224

43-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 5`] = `"Exhausted searching IDs in known runs, attempt 2..."`;
25+
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 5`] = `"Exhausted searching IDs in known runs, attempt 3..."`;
4426

4527
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 6`] = `"Attempting to get step names for Run IDs: [0]"`;
46-
47-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 7`] = `"Exhausted searching IDs in known runs, attempt 3..."`;
48-
49-
exports[`return-dispatch > handleAction > getRunIdAndUrl > should timeout when unable to find over time 8`] = `"Attempting to get step names for Run IDs: [0]"`;

src/main.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ describe("main", () => {
171171
startTime: Date.now(),
172172
branch: testBranch,
173173
distinctIdRegex: distinctIdRegex,
174-
workflow: testCfg.workflow,
175174
workflowId: 0,
176175
workflowTimeoutMs: testCfg.workflowTimeoutSeconds * 1000,
177176
});
@@ -187,12 +186,18 @@ describe("main", () => {
187186

188187
// Logging
189188
assertOnlyCalled(coreInfoLogMock, coreDebugLogMock);
190-
expect(coreInfoLogMock).toHaveBeenCalledOnce();
189+
expect(coreInfoLogMock).toHaveBeenCalledTimes(2);
191190
expect(coreInfoLogMock.mock.calls[0]?.[0]).toMatchInlineSnapshot(
192191
`"Attempt to extract branch name from ref..."`,
193192
);
194-
expect(coreDebugLogMock).toHaveBeenCalledOnce();
193+
expect(coreInfoLogMock.mock.calls[1]?.[0]).toMatchInlineSnapshot(
194+
`"Attempting to identify run ID from steps..."`,
195+
);
196+
expect(coreDebugLogMock).toHaveBeenCalledTimes(2);
195197
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatchInlineSnapshot(
198+
`"Attempting to identify run ID for test-workflow (0)"`,
199+
);
200+
expect(coreDebugLogMock.mock.calls[1]?.[0]).toMatchInlineSnapshot(
196201
`"Completed (0ms)"`,
197202
);
198203
});

src/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ export async function main(): Promise<void> {
3333

3434
const distinctIdRegex = createDistinctIdRegex(config.distinctId);
3535

36+
core.info("Attempting to identify run ID from steps...");
37+
core.debug(
38+
`Attempting to identify run ID for ${config.workflow} (${workflowId})`,
39+
);
40+
3641
const result = await getRunIdAndUrl({
3742
startTime,
3843
branch,
3944
distinctIdRegex,
40-
workflow: config.workflow,
4145
workflowId,
4246
workflowTimeoutMs: config.workflowTimeoutSeconds * 1000,
4347
});

src/return-dispatch.spec.ts

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ describe("return-dispatch", () => {
466466
describe("getRunIdAndUrl", () => {
467467
const distinctId = crypto.randomUUID();
468468
const distinctIdRegex = new RegExp(distinctId);
469-
const workflow = "workflow.yml";
470469
const workflowId = 123;
471470
const branch: utils.BranchNameResult = Object.freeze({
472471
isTag: false,
@@ -477,7 +476,6 @@ describe("return-dispatch", () => {
477476
startTime: Date.now(),
478477
branch: branch,
479478
distinctIdRegex: distinctIdRegex,
480-
workflow: workflow,
481479
workflowId: workflowId,
482480
workflowTimeoutMs: 100,
483481
};
@@ -547,13 +545,10 @@ describe("return-dispatch", () => {
547545
expect(utilSleepMock).not.toHaveBeenCalled();
548546

549547
// Logging
550-
assertOnlyCalled(coreDebugLogMock, coreInfoLogMock);
551-
expect(coreDebugLogMock).toHaveBeenCalledTimes(2);
548+
assertOnlyCalled(coreDebugLogMock);
549+
expect(coreDebugLogMock).toHaveBeenCalledOnce();
552550
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
553551
expect(coreDebugLogMock.mock.calls[1]?.[0]).toMatchSnapshot();
554-
555-
expect(coreInfoLogMock).toHaveBeenCalledOnce();
556-
expect(coreInfoLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
557552
});
558553

559554
it("should call retryOrTimeout with the larger WORKFLOW_FETCH_TIMEOUT_MS timeout value", async () => {
@@ -583,19 +578,11 @@ describe("return-dispatch", () => {
583578
expect(utilSleepMock).not.toHaveBeenCalled();
584579

585580
// Logging
586-
assertOnlyCalled(coreDebugLogMock, coreInfoLogMock);
587-
expect(coreDebugLogMock).toHaveBeenCalledTimes(2);
581+
assertOnlyCalled(coreDebugLogMock);
582+
expect(coreDebugLogMock).toHaveBeenCalledOnce();
588583
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatchInlineSnapshot(
589-
`"Attempting to identify run ID for workflow.yml (123)"`,
590-
);
591-
expect(coreDebugLogMock.mock.calls[1]?.[0]).toMatchInlineSnapshot(
592584
`"Attempting to get step names for Run IDs: [0]"`,
593585
);
594-
595-
expect(coreInfoLogMock).toHaveBeenCalledOnce();
596-
expect(coreInfoLogMock.mock.calls[0]?.[0]).toMatchInlineSnapshot(
597-
`"Attempting to identify run ID from steps..."`,
598-
);
599586
});
600587

601588
it("should call retryOrTimeout with the larger workflowTimeoutMs timeout value", async () => {
@@ -625,13 +612,9 @@ describe("return-dispatch", () => {
625612
expect(utilSleepMock).not.toHaveBeenCalled();
626613

627614
// Logging
628-
assertOnlyCalled(coreDebugLogMock, coreInfoLogMock);
629-
expect(coreDebugLogMock).toHaveBeenCalledTimes(2);
615+
assertOnlyCalled(coreDebugLogMock);
616+
expect(coreDebugLogMock).toHaveBeenCalledOnce();
630617
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
631-
expect(coreDebugLogMock.mock.calls[1]?.[0]).toMatchSnapshot();
632-
633-
expect(coreInfoLogMock).toHaveBeenCalledOnce();
634-
expect(coreInfoLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
635618
});
636619

637620
it("called fetchWorkflowRunIds with the provided workflowId and branch", async () => {
@@ -660,13 +643,9 @@ describe("return-dispatch", () => {
660643
);
661644

662645
// Logging
663-
assertOnlyCalled(coreDebugLogMock, coreInfoLogMock);
664-
expect(coreDebugLogMock).toHaveBeenCalledTimes(2);
646+
assertOnlyCalled(coreDebugLogMock);
647+
expect(coreDebugLogMock).toHaveBeenCalledOnce();
665648
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
666-
expect(coreDebugLogMock.mock.calls[1]?.[0]).toMatchSnapshot();
667-
668-
expect(coreInfoLogMock).toHaveBeenCalledOnce();
669-
expect(coreInfoLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
670649
});
671650

672651
it("should retry until an ID is found", async () => {
@@ -698,12 +677,8 @@ describe("return-dispatch", () => {
698677

699678
assertOnlyCalled(coreDebugLogMock, coreInfoLogMock);
700679

701-
expect(coreInfoLogMock).toHaveBeenCalledTimes(2);
680+
expect(coreInfoLogMock).toHaveBeenCalledOnce();
702681
expect(coreInfoLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
703-
expect(coreInfoLogMock.mock.calls[1]?.[0]).toMatchSnapshot();
704-
705-
expect(coreDebugLogMock).toHaveBeenCalledOnce();
706-
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
707682

708683
expect(utilSleepMock).toHaveBeenCalledOnce();
709684
expect(utilSleepMock).toHaveBeenCalledWith(5000);
@@ -780,15 +755,11 @@ describe("return-dispatch", () => {
780755
expect(utilSleepMock).not.toHaveBeenCalled();
781756

782757
// Logging
783-
assertOnlyCalled(coreDebugLogMock, coreInfoLogMock);
784-
expect(coreDebugLogMock).toHaveBeenCalledTimes(2);
785-
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
786-
expect(coreDebugLogMock.mock.calls[1]?.[0]).toMatch(
758+
assertOnlyCalled(coreDebugLogMock);
759+
expect(coreDebugLogMock).toHaveBeenCalledOnce();
760+
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatch(
787761
/Timed out while attempting to fetch Workflow Run IDs, waited [0-9]+ms/,
788762
);
789-
790-
expect(coreInfoLogMock).toHaveBeenCalledOnce();
791-
expect(coreInfoLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
792763
});
793764

794765
it("should timeout when unable to find over time", async () => {
@@ -817,13 +788,11 @@ describe("return-dispatch", () => {
817788
expect(apiFetchWorkflowRunJobStepsMock).toHaveBeenCalledOnce();
818789
assertOnlyCalled(coreDebugLogMock, coreInfoLogMock);
819790

820-
expect(coreInfoLogMock).toHaveBeenCalledTimes(2);
791+
expect(coreInfoLogMock).toHaveBeenCalledOnce();
821792
expect(coreInfoLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
822-
expect(coreInfoLogMock.mock.calls[1]?.[0]).toMatchSnapshot();
823793

824-
expect(coreDebugLogMock).toHaveBeenCalledTimes(2);
794+
expect(coreDebugLogMock).toHaveBeenCalledOnce();
825795
expect(coreDebugLogMock.mock.calls[0]?.[0]).toMatchSnapshot();
826-
expect(coreDebugLogMock.mock.calls[1]?.[0]).toMatchSnapshot();
827796

828797
expect(utilSleepMock).toHaveBeenCalledOnce();
829798
expect(utilSleepMock).toHaveBeenCalledWith(5000);

src/return-dispatch.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,13 @@ export interface GetRunIdAndUrlOpts {
127127
startTime: number;
128128
branch: BranchNameResult;
129129
distinctIdRegex: RegExp;
130-
workflow: string | number;
131130
workflowId: number;
132131
workflowTimeoutMs: number;
133132
}
134133
export async function getRunIdAndUrl({
135134
startTime,
136135
branch,
137136
distinctIdRegex,
138-
workflow,
139137
workflowId,
140138
workflowTimeoutMs,
141139
}: GetRunIdAndUrlOpts): Promise<Result<{ id: number; url: string }>> {
@@ -144,9 +142,6 @@ export async function getRunIdAndUrl({
144142
workflowTimeoutMs,
145143
);
146144

147-
core.info("Attempting to identify run ID from steps...");
148-
core.debug(`Attempting to identify run ID for ${workflow} (${workflowId})`);
149-
150145
let attemptNo = 0;
151146
let elapsedTime = Date.now() - startTime;
152147
while (elapsedTime < workflowTimeoutMs) {

0 commit comments

Comments
 (0)