From ae600ac2ed6370abd0f999a08c738007412a0dd1 Mon Sep 17 00:00:00 2001 From: Ben Coleman Date: Sun, 9 Aug 2020 22:45:13 +0100 Subject: [PATCH] changed mind about the workflow ref --- .github/workflows/build-test.yaml | 7 +++++++ src/main.ts | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 994c6a5..553e752 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -30,6 +30,13 @@ jobs: workflow: Message Echo 2 token: ${{ secrets.PERSONAL_TOKEN }} + - name: Invoke echo 1 workflow by id + uses: ./ + with: + workflow: '1854247' + token: ${{ secrets.PERSONAL_TOKEN }} + inputs: '{"message": "Mango jam"}' + - name: Update repo with build uses: mikeal/publish-to-github-action@master env: diff --git a/src/main.ts b/src/main.ts index 59ade63..49c3d54 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,7 +16,7 @@ async function run(): Promise { try { // Required inputs const token = core.getInput('token') - const workflowName = core.getInput('workflow') + const workflowRef = core.getInput('workflow') // Optional inputs, with defaults const ref = core.getInput('ref') || github.context.ref const [owner, repo] = core.getInput('repo') @@ -33,7 +33,7 @@ async function run(): Promise { // Get octokit client for making API calls const octokit = github.getOctokit(token) - // List workflows via API + // List workflows via API, and handle paginated results const workflows: ActionsGetWorkflowResponseData[] = await octokit.paginate(octokit.actions.listRepoWorkflows.endpoint.merge({ owner, repo, ref, inputs })) @@ -42,9 +42,9 @@ async function run(): Promise { core.debug(JSON.stringify(workflows, null, 3)) core.debug('### END: List Workflows response data') - // Locate workflow by name as we need it's id - const workflowFind = workflows.find((workflow) => workflow.name === workflowName) - if(!workflowFind) throw new Error(`Unable to find workflow named '${workflowName}' in ${owner}/${repo} 😥`) + // Locate workflow either by name or id + const workflowFind = workflows.find((workflow) => workflow.name === workflowRef || workflow.id.toString() === workflowRef) + if(!workflowFind) throw new Error(`Unable to find workflow '${workflowRef}' in ${owner}/${repo} 😥`) console.log(`Workflow id is: ${workflowFind.id}`) // Call workflow_dispatch API