Skip to content

Commit 04ff263

Browse files
committed
trigger-workflow-dispatch: use return_run_details when available
As announced in the GitHub changelog at https://github.blog/changelog/2026-02-19-workflow-dispatch-api-now-returns-run-ids/ the REST API's workflow dispatch endpoint now supports a boolean `return_run_details` parameter that, when set to `true`, causes the response to be a `200 OK` with a JSON body containing `workflow_run_id`, `run_url`, and `html_url` instead of the previous `204 No Content`. This eliminates the need to poll for the workflow run after triggering it, which was the root cause of the clock skew problems that this branch set out to fix (the polling required a time-based search window, and the response timestamp could come after the workflow run's `created_at`). The polling fallback is retained for robustness in case the API regresses or the parameter is not honored. The test mock returns the new `200` response for all dispatches except `upload-snapshot.yml`, which still returns the `204`-style response, so both code paths are exercised. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent fb14c06 commit 04ff263

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

GitForWindowsHelper/trigger-workflow-dispatch.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@ const triggerWorkflowDispatch = async (context, token, owner, repo, workflow_id,
3939
if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) {
4040
throw new Error(`Would have triggered workflow ${workflow_id} on ${owner}/${repo} with ref ${ref} and inputs ${JSON.stringify(inputs)}`)
4141
}
42-
const { headers: { date } } = await githubApiRequest(
42+
const response = await githubApiRequest(
4343
context,
4444
token,
4545
'POST',
4646
`/repos/${owner}/${repo}/actions/workflows/${workflow_id}/dispatches`,
47-
{ ref, inputs }
47+
{ ref, inputs, return_run_details: true }
4848
)
4949

50-
// to avoid any potential clock skew, we set the "after" time to 5 seconds before the current time
50+
// If the API returned run details (200), use them directly
51+
if (response.workflow_run_id) return response
52+
53+
// Fall back to polling if we got a 204 (no run details)
54+
const date = response.headers?.date || new Date().toISOString()
5155
const after = new Date(Date.parse(date) - 5000).toISOString()
5256
const runs = await waitForWorkflowRun(context, owner, repo, workflow_id, after, token)
5357
return runs[0]

__tests__/index.test.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ let mockGitHubApiRequest = jest.fn((_context, _token, method, requestPath, paylo
9191
path: `.github/workflows/${match[1]}`,
9292
payload
9393
})
94+
// Exercise the 204 fallback path for upload-snapshot.yml
95+
if (payload?.return_run_details && match[1] !== 'upload-snapshot.yml') return {
96+
workflow_run_id: 12345,
97+
run_url: `https://api.github.com/repos/test/test/actions/runs/12345`,
98+
html_url: `dispatched-workflow-${match[1]}`
99+
}
94100
return {
95101
headers: {
96102
date: (new Date()).toISOString()
@@ -338,14 +344,16 @@ The MINGW workflow run [was started](dispatched-workflow-open-pr.yml)`,
338344
expect(dispatchedWorkflows).toHaveLength(2)
339345
expect(dispatchedWorkflows.map(e => e.payload.inputs.package)).toEqual(['mingw-w64-gnutls', 'gnutls'])
340346
expect(mockGitHubApiRequest).toHaveBeenCalled()
341-
const msysComment = mockGitHubApiRequest.mock.calls[mockGitHubApiRequest.mock.calls.length - 6]
347+
const patchCalls = mockGitHubApiRequest.mock.calls.filter(c => c[2] === 'PATCH')
348+
expect(patchCalls).toHaveLength(2)
349+
const msysComment = patchCalls[0]
342350
expect(msysComment[3]).toEqual('/repos/git-for-windows/git/issues/comments/0')
343351
expect(msysComment[4]).toEqual({
344352
body: `existing comment body
345353
346354
The MSYS workflow run [was started](dispatched-workflow-open-pr.yml)`
347355
})
348-
const mingwComment = mockGitHubApiRequest.mock.calls[mockGitHubApiRequest.mock.calls.length - 1]
356+
const mingwComment = patchCalls[1]
349357
expect(mingwComment[3]).toEqual('/repos/git-for-windows/git/issues/comments/0')
350358
expect(mingwComment[4]).toEqual({
351359
body: `existing comment body
@@ -834,7 +842,8 @@ The \`git-artifacts-aarch64\` workflow run [was started](dispatched-workflow-git
834842
inputs: {
835843
architecture: 'i686',
836844
tag_git_workflow_run_id: "4322343196"
837-
}
845+
},
846+
return_run_details: true
838847
}
839848
])
840849
} catch (e) {
@@ -1041,7 +1050,8 @@ test('the third completed `git-artifacts-<arch>` check-run triggers an `upload-s
10411050
git_artifacts_aarch64_workflow_run_id: "13010016895",
10421051
git_artifacts_i686_workflow_run_id: "13010015938",
10431052
git_artifacts_x86_64_workflow_run_id: "13010015190"
1044-
}
1053+
},
1054+
return_run_details: true
10451055
}
10461056
])
10471057
} catch (e) {

0 commit comments

Comments
 (0)