From 5483d43b0d449444d870426ae232cd8758363ceb Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 14 Nov 2024 10:01:45 -0700 Subject: [PATCH] chore: api-reports + revert optional key change Signed-off-by: blam --- .changeset/wild-horses-refuse.md | 2 +- .../src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts | 9 ++------- .../src/scaffolder/tasks/NunjucksWorkflowRunner.ts | 4 +--- plugins/scaffolder-node/report.api.md | 8 ++++---- plugins/scaffolder-node/src/actions/types.ts | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/.changeset/wild-horses-refuse.md b/.changeset/wild-horses-refuse.md index 6d0657273c..bba991b057 100644 --- a/.changeset/wild-horses-refuse.md +++ b/.changeset/wild-horses-refuse.md @@ -3,7 +3,7 @@ '@backstage/plugin-scaffolder-node': minor --- -BREAKING ALPHA: The `checkpoint` method now takes an object instead of previous arguments, which allows also for an optional `key` which will be an incrementing counter for each call of the `checkpoint` method per step. +BREAKING ALPHA: The `checkpoint` method now takes an object instead of previous arguments. ```ts await ctx.checkpoint({ key: 'repo.create', fn: () => ockokit.repo.create({...})}) diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts index 24ec456223..9bef42b26a 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.test.ts @@ -166,17 +166,15 @@ describe('NunjucksWorkflowRunner', () => { }); const key4 = await ctx.checkpoint({ + key: 'key4', fn: () => {}, }); const key5 = await ctx.checkpoint({ + key: 'key5', fn: async () => {}, }); - const key6 = await ctx.checkpoint({ - fn: async () => 'look ma no key', - }); - ctx.output('key1', key1); ctx.output('key2', key2); ctx.output('key3', key3); @@ -185,8 +183,6 @@ describe('NunjucksWorkflowRunner', () => { ctx.output('key4', key4); // @ts-expect-error - this is void return ctx.output('key5', key5); - - ctx.output('key6', key6); }, }); @@ -688,7 +684,6 @@ describe('NunjucksWorkflowRunner', () => { expect(result.output.key3).toEqual('updated'); expect(result.output.key4).toEqual(undefined); expect(result.output.key5).toEqual(undefined); - expect(result.output.key6).toEqual('look ma no key'); }); it('should template the output from simple actions', async () => { diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts index 8a4cb8767f..c5413a08e0 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts @@ -364,7 +364,6 @@ export class NunjucksWorkflowRunner implements WorkflowRunner { )}`, ); } - let checkpointCount = 0; await action.handler({ input: iteration.input, @@ -377,8 +376,7 @@ export class NunjucksWorkflowRunner implements WorkflowRunner { key?: string; fn: () => Promise | T; }) { - const { key: checkpointKey = checkpointCount++, fn } = opts; - // default the task checkpoint to stepId plus count if there's no explict key provided. + const { key: checkpointKey, fn } = opts; const key = `v1.task.checkpoint.${step.id}.${checkpointKey}`; try { diff --git a/plugins/scaffolder-node/report.api.md b/plugins/scaffolder-node/report.api.md index 6328f94bfd..c7552a2eb6 100644 --- a/plugins/scaffolder-node/report.api.md +++ b/plugins/scaffolder-node/report.api.md @@ -31,10 +31,10 @@ export type ActionContext< secrets?: TaskSecrets; workspacePath: string; input: TActionInput; - checkpoint( - key: string, - fn: () => Promise, - ): Promise; + checkpoint(opts: { + key: string; + fn: () => Promise | U; + }): Promise; output( name: keyof TActionOutput, value: TActionOutput[keyof TActionOutput], diff --git a/plugins/scaffolder-node/src/actions/types.ts b/plugins/scaffolder-node/src/actions/types.ts index f24dc154e2..90a8a741b0 100644 --- a/plugins/scaffolder-node/src/actions/types.ts +++ b/plugins/scaffolder-node/src/actions/types.ts @@ -39,7 +39,7 @@ export type ActionContext< workspacePath: string; input: TActionInput; checkpoint(opts: { - key?: string; + key: string; fn: () => Promise | U; }): Promise; output(