@@ -3,6 +3,7 @@ import * as github from '@actions/github'
33import { getConfig , ActionConfig , DispatchMethod } from '../action'
44import { getBranchNameFromRef } from '../utils'
55import { Octokit , WorkflowRun , WorkflowRunResponse } from './api.types'
6+ import type { OctokitResponse } from '@octokit/types'
67
78let config : ActionConfig
89let octokit : Octokit
@@ -25,18 +26,26 @@ export async function workflowDispatch(distinctId: string): Promise<void> {
2526 if ( ! config . ref ) {
2627 throw new Error ( `workflow_dispatch: An input to 'ref' was not provided` )
2728 }
28- // https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
29- const response = await octokit . rest . actions . createWorkflowDispatch ( {
29+ // GitHub released a breaking change to the createWorkflowDispatch API that resulted in a change where the returned
30+ // status code changed to 200, from 204. At the time, the @octokit/types had not been updated to reflect this change.
31+ //
32+ // Given that we are in an interim state where the API behaviour, but the public documentation has not been updated
33+ // to reflect this change, and GitHub has not yet released any updates on this topic. I can going to play the safe
34+ // route and assume that the response status code could be either 200 or 204.
35+ //
36+ // Reference: https://github.com/orgs/community/discussions/9752#discussioncomment-15295321
37+ // Documentation: https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
38+ const response = ( await octokit . rest . actions . createWorkflowDispatch ( {
3039 owner : config . owner ,
3140 repo : config . repo ,
3241 workflow_id : config . workflow ,
3342 ref : config . ref ,
3443 inputs
35- } )
44+ } ) ) as OctokitResponse < never , 204 | 200 >
3645
37- if ( response . status !== 204 ) {
46+ if ( response . status !== 200 && response . status !== 204 ) {
3847 throw new Error (
39- `workflow_dispatch: Failed to dispatch action, expected 204 but received ${ response . status } `
48+ `workflow_dispatch: Failed to dispatch action, expected 200 or 204 but received ${ response . status } `
4049 )
4150 }
4251
0 commit comments