Skip to content

Commit ae600ac

Browse files
committed
changed mind about the workflow ref
1 parent 228ff68 commit ae600ac

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

.github/workflows/build-test.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ jobs:
3030
workflow: Message Echo 2
3131
token: ${{ secrets.PERSONAL_TOKEN }}
3232

33+
- name: Invoke echo 1 workflow by id
34+
uses: ./
35+
with:
36+
workflow: '1854247'
37+
token: ${{ secrets.PERSONAL_TOKEN }}
38+
inputs: '{"message": "Mango jam"}'
39+
3340
- name: Update repo with build
3441
uses: mikeal/publish-to-github-action@master
3542
env:

src/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function run(): Promise<void> {
1616
try {
1717
// Required inputs
1818
const token = core.getInput('token')
19-
const workflowName = core.getInput('workflow')
19+
const workflowRef = core.getInput('workflow')
2020
// Optional inputs, with defaults
2121
const ref = core.getInput('ref') || github.context.ref
2222
const [owner, repo] = core.getInput('repo')
@@ -33,7 +33,7 @@ async function run(): Promise<void> {
3333
// Get octokit client for making API calls
3434
const octokit = github.getOctokit(token)
3535

36-
// List workflows via API
36+
// List workflows via API, and handle paginated results
3737
const workflows: ActionsGetWorkflowResponseData[] =
3838
await octokit.paginate(octokit.actions.listRepoWorkflows.endpoint.merge({ owner, repo, ref, inputs }))
3939

@@ -42,9 +42,9 @@ async function run(): Promise<void> {
4242
core.debug(JSON.stringify(workflows, null, 3))
4343
core.debug('### END: List Workflows response data')
4444

45-
// Locate workflow by name as we need it's id
46-
const workflowFind = workflows.find((workflow) => workflow.name === workflowName)
47-
if(!workflowFind) throw new Error(`Unable to find workflow named '${workflowName}' in ${owner}/${repo} 😥`)
45+
// Locate workflow either by name or id
46+
const workflowFind = workflows.find((workflow) => workflow.name === workflowRef || workflow.id.toString() === workflowRef)
47+
if(!workflowFind) throw new Error(`Unable to find workflow '${workflowRef}' in ${owner}/${repo} 😥`)
4848
console.log(`Workflow id is: ${workflowFind.id}`)
4949

5050
// Call workflow_dispatch API

0 commit comments

Comments
 (0)