Skip to content

Commit

Permalink
changed mind about the workflow ref
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-uk committed Aug 9, 2020
1 parent 228ff68 commit ae600ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function run(): Promise<void> {
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')
Expand All @@ -33,7 +33,7 @@ async function run(): Promise<void> {
// 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 }))

Expand All @@ -42,9 +42,9 @@ async function run(): Promise<void> {
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
Expand Down

0 comments on commit ae600ac

Please sign in to comment.