@@ -6,7 +6,8 @@ async function run(): Promise<void> {
66 try {
77 // Required inputs
88 const token = core . getInput ( 'token' )
9- const workflowName = core . getInput ( 'workflow' )
9+ const workflowReference = core . getInput ( 'workflow' )
10+ const workflowIdFlag = core . getInput ( 'use-workflow-id' ) || 'false'
1011 // Optional inputs, with defaults
1112 const ref = core . getInput ( 'ref' ) || github . context . ref
1213 const repo = core . getInput ( 'repo' ) || `${ github . context . repo . owner } /${ github . context . repo . repo } `
@@ -21,25 +22,33 @@ async function run(): Promise<void> {
2122 // Get octokit client for making API calls
2223 const octokit = github . getOctokit ( token )
2324
24- // List workflows via API
25- const listResp = await octokit . request ( `GET /repos/${ repo } /actions/workflows` , {
26- ref : ref ,
27- inputs : inputs
28- } )
29- if ( listResp . status != 200 ) throw new Error ( `Got HTTP ${ listResp . status } calling list workflows API 💩` )
30-
31- // Debug response if ACTIONS_STEP_DEBUG is enabled
32- core . debug ( listResp . data )
25+ let workflowId = ''
26+ if ( workflowIdFlag !== 'true' ) {
27+ // List workflows via API
28+ const listResp = await octokit . request ( `GET /repos/${ repo } /actions/workflows` , {
29+ ref : ref ,
30+ inputs : inputs
31+ } )
32+ if ( listResp . status != 200 ) throw new Error ( `Got HTTP ${ listResp . status } calling list workflows API 💩` )
33+
34+ // Debug response if ACTIONS_STEP_DEBUG is enabled
35+ core . debug ( listResp . data )
36+
37+ // Locate workflow by name as we need it's id
38+ const foundWorkflow = listResp . data . workflows . find ( ( wf : Record < string , string > ) => {
39+ return wf [ 'name' ] === workflowReference
40+ } )
41+ if ( ! foundWorkflow ) throw new Error ( `Unable to find workflow named '${ workflowReference } ' in ${ repo } 😥` )
42+
43+ workflowId = foundWorkflow . id
44+ } else {
45+ workflowId = workflowReference
46+ }
3347
34- // Locate workflow by name as we need it's id
35- const workflowFind = listResp . data . workflows . find ( ( wf : Record < string , string > ) => {
36- return wf [ 'name' ] === workflowName
37- } )
38- if ( ! workflowFind ) throw new Error ( `Unable to find workflow named '${ workflowName } ' in ${ repo } 😥` )
39- console . log ( `Workflow id is: ${ workflowFind . id } ` )
48+ console . log ( `Workflow id is: ${ workflowId } ` )
4049
4150 // Call workflow_dispatch API
42- const dispatchResp = await octokit . request ( `POST /repos/${ repo } /actions/workflows/${ workflowFind . id } /dispatches` , {
51+ const dispatchResp = await octokit . request ( `POST /repos/${ repo } /actions/workflows/${ workflowId } /dispatches` , {
4352 ref : ref ,
4453 inputs : inputs
4554 } )
0 commit comments