From 2cd42a7ae54bc6100272db7f7e6fa4ff1251c07e Mon Sep 17 00:00:00 2001 From: Tracey Date: Wed, 19 Jan 2022 14:57:06 -0700 Subject: [PATCH 1/4] updated github:action:dispatch to include inputs to send to GitHub action Signed-off-by: Tracey --- .../github/githubActionsDispatch.test.ts | 29 ++++++++++++++++++- .../builtin/github/githubActionsDispatch.ts | 10 ++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts index b725f825fe..6cdb2ee58c 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts @@ -66,7 +66,7 @@ describe('github:actions:dispatch', () => { }); }); - it('should call the githubApis for creating WorkflowDispatch', async () => { + it('should call the githubApis for creating WorkflowDispatch without an input object', async () => { mockGithubClient.rest.actions.createWorkflowDispatch.mockResolvedValue({ data: { foo: 'bar', @@ -90,4 +90,31 @@ describe('github:actions:dispatch', () => { ref: branchOrTagName, }); }); + + it('should call the githubApis for creating WorkflowDispatch with an input object', async () => { + mockGithubClient.rest.actions.createWorkflowDispatch.mockResolvedValue({ + data: { + foo: 'bar', + }, + }); + + const repoUrl = 'github.com?repo=repo&owner=owner'; + const workflowId = 'dispatch_workflow'; + const branchOrTagName = 'main'; + const workflowInputs = '{ "foo": "bar" }'; + const ctx = Object.assign({}, mockContext, { + input: { repoUrl, workflowId, branchOrTagName, workflowInputs }, + }); + await action.handler(ctx); + + expect( + mockGithubClient.rest.actions.createWorkflowDispatch, + ).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + workflow_id: workflowId, + ref: branchOrTagName, + inputs: workflowInputs, + }); + }); }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts index eed74f2d04..43339ba5d3 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts @@ -36,6 +36,7 @@ export function createGithubActionsDispatchAction(options: { repoUrl: string; workflowId: string; branchOrTagName: string; + workflowInputs?: { [key: string]: string }; }>({ id: 'github:actions:dispatch', description: @@ -61,11 +62,17 @@ export function createGithubActionsDispatchAction(options: { 'The git branch or tag name used to dispatch the workflow', type: 'string', }, + workflowInputs: { + title: 'Workflow Inputs', + description: + 'Inputs keys and values to send to GitHub Action configured on the workflow file. The maximum number of properties is 10. Any default properties configured in the workflow file will be used when inputs are omitted.', + }, }, }, }, async handler(ctx) { - const { repoUrl, workflowId, branchOrTagName } = ctx.input; + const { repoUrl, workflowId, branchOrTagName, workflowInputs } = + ctx.input; ctx.logger.info( `Dispatching workflow ${workflowId} for repo ${repoUrl} on ${branchOrTagName}`, @@ -78,6 +85,7 @@ export function createGithubActionsDispatchAction(options: { repo, workflow_id: workflowId, ref: branchOrTagName, + inputs: workflowInputs, }); ctx.logger.info(`Workflow ${workflowId} dispatched successfully`); From ac2f1eeec0150b5036353d74dce6747e7a3598a1 Mon Sep 17 00:00:00 2001 From: Tracey Date: Wed, 19 Jan 2022 15:05:07 -0700 Subject: [PATCH 2/4] comitting changeset Signed-off-by: Tracey --- .changeset/eight-tools-sleep.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eight-tools-sleep.md diff --git a/.changeset/eight-tools-sleep.md b/.changeset/eight-tools-sleep.md new file mode 100644 index 0000000000..f2fc16f12e --- /dev/null +++ b/.changeset/eight-tools-sleep.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +This change is for adding the option of inputs on the github:actions:dispatch Backstage Action. This will allow users to pass data from Backstage to the GitHub Action. From b1b5639b867f56e7d17fc2671c0b7c56fdbe6590 Mon Sep 17 00:00:00 2001 From: Tracey Date: Mon, 24 Jan 2022 14:01:17 -0800 Subject: [PATCH 3/4] shortened description, added type to workflowInputs and fixed line issue in handler Signed-off-by: Tracey --- .../scaffolder/actions/builtin/github/githubActionsDispatch.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts index 43339ba5d3..1f7f0f60b9 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.ts @@ -65,7 +65,8 @@ export function createGithubActionsDispatchAction(options: { workflowInputs: { title: 'Workflow Inputs', description: - 'Inputs keys and values to send to GitHub Action configured on the workflow file. The maximum number of properties is 10. Any default properties configured in the workflow file will be used when inputs are omitted.', + 'Inputs keys and values to send to GitHub Action configured on the workflow file. The maximum number of properties is 10. ', + type: 'object', }, }, }, From 16b925ed4d3c09dd88c25a22b10d77bd3b23ce99 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 26 Jan 2022 19:00:18 +0100 Subject: [PATCH 4/4] Update eight-tools-sleep.md Signed-off-by: Patrik Oldsberg --- .changeset/eight-tools-sleep.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/eight-tools-sleep.md b/.changeset/eight-tools-sleep.md index f2fc16f12e..9de43e8862 100644 --- a/.changeset/eight-tools-sleep.md +++ b/.changeset/eight-tools-sleep.md @@ -2,4 +2,4 @@ '@backstage/plugin-scaffolder-backend': patch --- -This change is for adding the option of inputs on the github:actions:dispatch Backstage Action. This will allow users to pass data from Backstage to the GitHub Action. +This change is for adding the option of inputs on the `github:actions:dispatch` Backstage Action. This will allow users to pass data from Backstage to the GitHub Action.