Skip to content

Commit 3bbd17e

Browse files
Merge pull request #37 from step-security/auto-cherry-pick
chore: Cherry-picked changes from upstream
2 parents 247445d + 1019b90 commit 3bbd17e

File tree

8 files changed

+68
-26
lines changed

8 files changed

+68
-26
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.6.0
1+
20.19.6

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ There was a need for this action as currently available actions...
1717

1818
```yaml
1919
steps:
20-
- uses: step-security/dispatch-workflow@v1
20+
- uses: step-security/dispatch-workflow@v2
2121
id: workflow-dispatch
2222
name: 'Dispatch Workflow using workflow_dispatch Method'
2323
with:
@@ -39,7 +39,7 @@ steps:
3939

4040
```yaml
4141
steps:
42-
- uses: step-security/dispatch-workflow@v1
42+
- uses: step-security/dispatch-workflow@v2
4343
id: repository-dispatch
4444
name: 'Dispatch Workflow using repository_dispatch Method'
4545
with:
@@ -120,7 +120,7 @@ This functionality is **disabled by default**, but can be enabled with the `disc
120120

121121
```yaml
122122
steps:
123-
- uses: step-security/dispatch-workflow@v1
123+
- uses: step-security/dispatch-workflow@v2
124124
id: dispatch-with-discovery
125125
name: "Dispatch Workflow With Discovery"
126126
with:
@@ -224,7 +224,7 @@ By default, this GitHub Action has no outputs. However, when discovery mode is *
224224

225225
```yaml
226226
steps:
227-
- uses: step-security/dispatch-workflow@v1
227+
- uses: step-security/dispatch-workflow@v2
228228
id: wait-repository-dispatch
229229
name: 'Dispatch Using repository_dispatch Method And Wait For Run-ID'
230230
with:
@@ -286,7 +286,7 @@ types must be wrapped in **quotes** to successfully dispatch the workflow.
286286

287287
```yaml
288288
# Invalid ❌
289-
- uses: step-security/dispatch-workflow@v1
289+
- uses: step-security/dispatch-workflow@v2
290290
id: workflow-dispatch
291291
name: 'Dispatch Using workflow_dispatch Method'
292292
with:
@@ -299,7 +299,7 @@ types must be wrapped in **quotes** to successfully dispatch the workflow.
299299
}
300300
301301
# Valid 🟢
302-
- uses: step-security/dispatch-workflow@v1
302+
- uses: step-security/dispatch-workflow@v2
303303
id: workflow-dispatch
304304
name: 'Dispatch Using workflow_dispatch Method'
305305
with:
@@ -323,7 +323,7 @@ When interacting with the GitHub REST API, it's beneficial to handle potential f
323323
- `time-multiple`: The factor by which the `starting-delay-ms` is multiplied for each reattempt, influencing the delay duration.
324324

325325
```yaml
326-
- uses: step-security/dispatch-workflow@v1
326+
- uses: step-security/dispatch-workflow@v2
327327
id: custom-backoff
328328
name: 'Dispatch with custom exponential backoff parameters'
329329
with:

dist/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,24 @@ function workflowDispatch(distinctId) {
293293
if (!config.ref) {
294294
throw new Error(`workflow_dispatch: An input to 'ref' was not provided`);
295295
}
296-
// https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
297-
const response = yield octokit.rest.actions.createWorkflowDispatch({
296+
// GitHub released a breaking change to the createWorkflowDispatch API that resulted in a change where the returned
297+
// status code changed to 200, from 204. At the time, the @octokit/types had not been updated to reflect this change.
298+
//
299+
// Given that we are in an interim state where the API behaviour, but the public documentation has not been updated
300+
// to reflect this change, and GitHub has not yet released any updates on this topic. I can going to play the safe
301+
// route and assume that the response status code could be either 200 or 204.
302+
//
303+
// Reference: https://github.com/orgs/community/discussions/9752#discussioncomment-15295321
304+
// Documentation: https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
305+
const response = (yield octokit.rest.actions.createWorkflowDispatch({
298306
owner: config.owner,
299307
repo: config.repo,
300308
workflow_id: config.workflow,
301309
ref: config.ref,
302310
inputs
303-
});
304-
if (response.status !== 204) {
305-
throw new Error(`workflow_dispatch: Failed to dispatch action, expected 204 but received ${response.status}`);
311+
}));
312+
if (response.status !== 200 && response.status !== 204) {
313+
throw new Error(`workflow_dispatch: Failed to dispatch action, expected 200 or 204 but received ${response.status}`);
306314
}
307315
core.info(`✅ Successfully dispatched workflow using workflow_dispatch method:
308316
repository: ${config.owner}/${config.repo}

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dispatch-workflow",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"private": true,
55
"description": "A GitHub action to dispatch a remote GitHub workflow and optionally retrieve its information",
66
"main": "lib/index.js",

src/api/api.test.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,32 @@ describe('API', () => {
8585
init(mockActionConfig)
8686
})
8787

88-
it('should resolve after a successful dispatch', async () => {
88+
// GitHub released a breaking change to the createWorkflowDispatch API that resulted in a change where the returned
89+
// status code changed to 200, from 204.
90+
//
91+
// Given that we are in an interim state where the API behaviour, but the public documentation has not been updated
92+
// to reflect this change, and GitHub has not yet released any updates on this topic. I can going to play the safe
93+
// route and assume that the response status code could be either 200 or 204. I've added a test case that supports both
94+
// potential status codes.
95+
//
96+
// Reference: https://github.com/orgs/community/discussions/9752#discussioncomment-15295321
97+
// Documentation: https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event
98+
it('should resolve after a successful dispatch with a 200 status', async () => {
99+
jest
100+
.spyOn(mockOctokit.rest.actions, 'createWorkflowDispatch')
101+
.mockReturnValue(
102+
Promise.resolve({
103+
headers: null,
104+
url: '',
105+
data: undefined,
106+
status: 200
107+
})
108+
)
109+
110+
await workflowDispatch('')
111+
})
112+
113+
it('should resolve after a successful dispatch with a 204 status', async () => {
89114
jest
90115
.spyOn(mockOctokit.rest.actions, 'createWorkflowDispatch')
91116
.mockReturnValue(
@@ -112,7 +137,7 @@ describe('API', () => {
112137
)
113138

114139
await expect(workflowDispatch('')).rejects.toThrow(
115-
`Failed to dispatch action, expected 204 but received ${errorStatus}`
140+
`Failed to dispatch action, expected 200 or 204 but received ${errorStatus}`
116141
)
117142
})
118143

@@ -126,7 +151,7 @@ describe('API', () => {
126151

127152
return {
128153
data: undefined,
129-
status: 204
154+
status: 200
130155
}
131156
})
132157

@@ -147,7 +172,7 @@ describe('API', () => {
147172

148173
return {
149174
data: undefined,
150-
status: 204
175+
status: 200
151176
}
152177
})
153178

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)