Use workflow_dispatch return_run_details to get run ID directly#19414
Use workflow_dispatch return_run_details to get run ID directly#19414
Conversation
…_dispatch Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
pkg/cli/run_workflow_execution.go
Outdated
|
|
||
| // runInfoURLRegexp matches GitHub Actions run URLs of the form: | ||
| // https://github.com/{owner}/{repo}/actions/runs/{run_id} | ||
| var runInfoURLRegexp = regexp.MustCompile(`https://github\.com/[^/\s]+/[^/\s]+/actions/runs/(\d+)`) |
There was a problem hiding this comment.
Updated the regex in parseRunInfoFromOutput to match any HTTPS host instead of hardcoding github.com, so it works for GitHub Enterprise Server deployments (e.g., https://github.mycompany.com/...) automatically. Added GHES test cases to cover this. See commit c2e1f35.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates workflow dispatch/run tooling to capture GitHub Actions run IDs immediately (via newer APIs/CLI output) and avoid post-dispatch polling when possible.
Changes:
- Add parsing of
gh workflow runoutput to extract the run URL/ID directly, with polling fallback for older gh versions. - Update the JS
dispatch_workflowhandler to requestworkflow_run_idviareturn_run_details: true, log it, and return it in the handler result. - Add/adjust unit tests covering run-info parsing and returned
run_id.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/cli/run_workflow_execution.go | Parse run URL/ID from gh workflow run output; fallback to existing polling logic. |
| pkg/cli/run_workflow_execution_test.go | Add unit tests for extracting run info from gh output. |
| actions/setup/js/dispatch_workflow.cjs | Request run details on dispatch; log and return run_id when present. |
| actions/setup/js/dispatch_workflow.test.cjs | Update mocks/assertions for return_run_details + add tests for run_id handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const response = await githubClient.rest.actions.createWorkflowDispatch({ | ||
| owner: repo.owner, | ||
| repo: repo.repo, | ||
| workflow_id: workflowFile, | ||
| ref: ref, | ||
| inputs: inputs, | ||
| return_run_details: true, | ||
| }); |
There was a problem hiding this comment.
return_run_details: true is always sent to the REST API. Since this repo supports GitHub Enterprise (see many handlers using GITHUB_SERVER_URL), older GHES versions that don’t implement the Feb 2026 return_run_details parameter may reject the request (e.g., 400/422), causing dispatch to fail entirely. Consider attempting the dispatch with return_run_details: true and, on a validation/unknown-parameter error, retry once without return_run_details so dispatch remains backward compatible while still taking advantage of run IDs when supported.
See below for a potential fix:
/** @type {import('@octokit/openapi-types').components["schemas"]["workflow-run"] | any} */
let response;
try {
response = await githubClient.rest.actions.createWorkflowDispatch({
owner: repo.owner,
repo: repo.repo,
workflow_id: workflowFile,
ref: ref,
inputs: inputs,
return_run_details: true,
});
} catch (dispatchError) {
const status = dispatchError && typeof dispatchError === "object" ? dispatchError.status : undefined;
const message =
dispatchError &&
typeof dispatchError === "object" &&
dispatchError.response &&
dispatchError.response.data &&
typeof dispatchError.response.data.message === "string"
? dispatchError.response.data.message
: String(dispatchError);
const isValidationStatus = status === 400 || status === 422;
const mentionsReturnRunDetails =
typeof message === "string" && message.toLowerCase().includes("return_run_details");
if (isValidationStatus && mentionsReturnRunDetails) {
core.info(
"Workflow dispatch failed due to unsupported 'return_run_details' parameter; retrying without it for GitHub Enterprise compatibility."
);
response = await githubClient.rest.actions.createWorkflowDispatch({
owner: repo.owner,
repo: repo.repo,
workflow_id: workflowFile,
ref: ref,
inputs: inputs,
});
} else {
throw dispatchError;
}
}
const runId = response && response.data ? response.data.workflow_run_id : undefined;
|
@copilot review comments |
…lity Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed both review comments in commit 329c17f:
|
|
🌑 The shadows whisper... Smoke Codex failed. The oracle requires further meditation... |
|
🎬 THE END — Smoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨ |
|
📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing... |
|
Commit pushed:
|
Agent Container Tool Check
Result: 12/12 tools available ✅ Overall Status: PASS
|
|
✅ #19414 – Use workflow_dispatch return_run_details to get run ID directly Overall: PASS (11/12 — Serena MCP unavailable)
|
There was a problem hiding this comment.
Clean implementation of return_run_details support with graceful GHES fallback. The JS side correctly handles the API response and propagates run_id in the result. The Go side's parseRunInfoFromOutput eliminates polling overhead for modern gh CLI users while maintaining backward compatibility. Overall a well-structured change.
📰 BREAKING: Report filed by Smoke Copilot
| const isValidationStatus = status === 400 || status === 422; | ||
| const mentionsReturnRunDetails = typeof message === "string" && message.toLowerCase().includes("return_run_details"); | ||
|
|
||
| if (isValidationStatus && mentionsReturnRunDetails) { |
There was a problem hiding this comment.
The dual condition check (isValidationStatus && mentionsReturnRunDetails) is a great defensive approach — it prevents masking other 400/422 errors while still catching GHES-specific rejection of return_run_details. The message substring check could be brittle if GitHub changes the error wording, but this is a reasonable pragmatic tradeoff for compatibility.
| // output of `gh workflow run` (v2.87+), which now returns the run URL. | ||
| // Returns nil if the run URL cannot be found in the output. | ||
| func parseRunInfoFromOutput(output string) *WorkflowRunInfo { | ||
| matches := runInfoURLRegexp.FindStringSubmatch(output) |
There was a problem hiding this comment.
The regex https://[^/\s]+/[^/\s]+/[^/\s]+/actions/runs/(\d+) correctly handles both github.com and GHES URLs. Nice use of FindStringSubmatch with fallback to nil — keeps the function cleanly nil-safe and integrates well with the caller's conditional logic.
|
📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤 |
Smoke Test Results — Run §22624132898Overall: PARTIAL (16 passed, 1 skipped) Core Tests
PR Review Tests
|
There was a problem hiding this comment.
💥 Automated smoke test review - all systems nominal!
💥 [THE END] — Illustrated by Smoke Claude
The GitHub workflow_dispatch API (Feb 2026) now supports returning the run ID immediately via
return_run_details: true, eliminating the need to pollgh run listafter triggering a dispatch.dispatch_workflow.cjsreturn_run_details: truetocreateWorkflowDispatch()workflow_run_idand include it in the handler resultreturn_run_details, retry once without the parameter so dispatch continues to work on GHES versions that don't support the Feb 2026 APIrun_workflow_execution.gogh workflow run(v2.87+) now prints the run URL in stdout; parse the run ID from it directly instead of polling viagetLatestWorkflowRunWithRetrygithub.com) and GitHub Enterprise Server deployments (any HTTPS host)Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
✨ PR Review Safe Output Test - Run 22623479111
Use workflow_dispatch return_run_details to get run ID directly
dispatch_workflow.cjs: passreturn_run_details: truetocreateWorkflowDispatch()and log the run IDrun_workflow_execution.go: parse run ID fromgh workflow runstdout output (new in v2.87+), fall back to polling for backward compatibilityparseRunInfoFromOutputhelper function with generic URL regex supporting all GitHub deployments (public + enterprise)dispatch_workflow.cjsto assertreturn_run_details: true, verify run_id in result, test no-run-id backward compatTestParseRunInfoFromOutputunit tests including GHES URL casesdispatch_workflow.cjs: if API returns 400/422 mentioningreturn_run_details, retry without it for older GHES compatibilityreturn_run_detailsmention → retry; 422 for unrelated reason → no retry)Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey]((gh.io/redacted)
✨ PR Review Safe Output Test - Run 22623479111
Changeset
Warning
The following domain was blocked by the firewall during workflow execution:
github.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.