From a833f0f46d894340edefa0f2d47361d9cdc4e932 Mon Sep 17 00:00:00 2001 From: Bogdan Nechyporenko Date: Tue, 18 Mar 2025 20:26:33 +0100 Subject: [PATCH] Made "github:actions:dispatch" action idempotent Signed-off-by: Bogdan Nechyporenko --- .changeset/twenty-walls-join.md | 5 +++++ .../src/actions/githubActionsDispatch.ts | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 .changeset/twenty-walls-join.md diff --git a/.changeset/twenty-walls-join.md b/.changeset/twenty-walls-join.md new file mode 100644 index 0000000000..2282e28775 --- /dev/null +++ b/.changeset/twenty-walls-join.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-github': patch +--- + +Made "github:actions:dispatch" action idempotent diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubActionsDispatch.ts b/plugins/scaffolder-backend-module-github/src/actions/githubActionsDispatch.ts index 8e185a9567..4faa53e6b8 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubActionsDispatch.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubActionsDispatch.ts @@ -115,15 +115,20 @@ export function createGithubActionsDispatchAction(options: { }), ); - await client.rest.actions.createWorkflowDispatch({ - owner, - repo, - workflow_id: workflowId, - ref: branchOrTagName, - inputs: workflowInputs, - }); + await ctx.checkpoint({ + key: `create.workflow.dispatch.${owner}.${repo}.${workflowId}`, + fn: async () => { + await client.rest.actions.createWorkflowDispatch({ + owner, + repo, + workflow_id: workflowId, + ref: branchOrTagName, + inputs: workflowInputs, + }); - ctx.logger.info(`Workflow ${workflowId} dispatched successfully`); + ctx.logger.info(`Workflow ${workflowId} dispatched successfully`); + }, + }); }, }); }