Skip to content

Commit 2186a33

Browse files
(feat): Add safe-guard against a 200 response from createWorkflowDispatch
1 parent 10bff68 commit 2186a33

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/api/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as github from '@actions/github'
33
import {getConfig, ActionConfig, DispatchMethod} from '../action'
44
import {getBranchNameFromRef} from '../utils'
55
import {Octokit, WorkflowRun, WorkflowRunResponse} from './api.types'
6+
import type {OctokitResponse} from '@octokit/types'
67

78
let config: ActionConfig
89
let 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

Comments
 (0)