import * as core from '@actions/core' ; import * as github from '@actions/github' ; import { ActionsGetWorkflowResponseData } from '@octokit/types' ; async function run ( ) { try { const token = core . getInput ( 'token' ) ; const workflowRef = core . getInput ( 'workflow' ) ; const ref = core . getInput ( 'ref' ) || github . context . ref ; const [ owner , repo ] = core . getInput ( 'repo' ) ? core . getInput ( 'repo' ) . split ( '/' ) : [ github . context . repo . owner , github . context . repo . repo ] ; let inputs = { } ; const inputsJson = core . getInput ( 'inputs' ) ; if ( inputsJson ) { inputs = JSON . parse ( inputsJson ) ; } const octokit = github . getOctokit ( token ) ; const workflows = await octokit . paginate ( octokit . actions . listRepoWorkflows . endpoint . merge ( { owner , repo , ref , inputs } ) ) ; core . debug ( '### START List Workflows response data' ) ; core . debug ( JSON . stringify ( workflows , null , 3 ) ) ; core . debug ( '### END:  List Workflows response data' ) ; 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 }` ) ; const dispatchResp = await octokit . request ( `POST /repos/${ owner }/${ repo }/actions/workflows/${ workflowFind . id }/dispatches` , { ref : ref , inputs : inputs } ) ; core . info ( `API response status: ${ dispatchResp . status } 🚀` ) ; } catch ( error ) { core . setFailed ( error . message ) ; } } run ( ) ;