Skip to content

Commit 82e6597

Browse files
authored
fix: add tolerance for ambiguous behavior in gh run list (#4162)
I am not sure what is going on, as #3660 introduced this new logic and I swear that CI was green before I merged that PR, but I am seeing failures in this CI job this morning. This feels like a non-backwards-compatible change in `gh`, but that feels unlikely... Nevertheless, this is what I currently see on my laptop: ``` $ gh --version gh version 2.76.2 (2025-07-30) https://github.com/cli/cli/releases/tag/v2.76.2 $ gh run list --workflow .github/workflows/rust-release.yml --branch rust-v0.40.0 --json workflowName,url,headSha --jq 'first(.[])' { "headSha": "5268705a69713752adcbd8416ef9e84a683f7aa3", "url": "https://github.com/openai/codex/actions/runs/17952349351", "workflowName": ".github/workflows/rust-release.yml" } ``` Looking at sample output from an old GitHub issue (cli/cli#6678), it appears that, at least at one point in time, the `workflowName` was _not_ the path to the workflow.
1 parent 639a6fd commit 82e6597

1 file changed

Lines changed: 11 additions & 36 deletions

File tree

‎codex-cli/scripts/build_npm_package.py‎

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
REPO_ROOT = CODEX_CLI_ROOT.parent
1616
GITHUB_REPO = "openai/codex"
1717

18+
# The docs are not clear on what the expected value/format of
19+
# workflow/workflowName is:
20+
# https://cli.github.com/manual/gh_run_list
21+
WORKFLOW_NAME = ".github/workflows/rust-release.yml"
22+
1823

1924
def parse_args() -> argparse.Namespace:
2025
parser = argparse.ArgumentParser(description="Build or stage the Codex CLI npm package.")
@@ -163,10 +168,8 @@ def install_native_binaries(staging_dir: Path, workflow_url: str | None) -> None
163168

164169
def resolve_latest_alpha_workflow_url() -> str:
165170
version = determine_latest_alpha_version()
166-
workflow_url = fetch_workflow_url_for_version(version)
167-
if not workflow_url:
168-
raise RuntimeError(f"Unable to locate workflow for version {version}.")
169-
return workflow_url
171+
workflow = resolve_release_workflow(version)
172+
return workflow["url"]
170173

171174

172175
def determine_latest_alpha_version() -> str:
@@ -205,36 +208,6 @@ def list_releases() -> list[dict]:
205208
return releases
206209

207210

208-
def fetch_workflow_url_for_version(version: str) -> str | None:
209-
ref = f"rust-v{version}"
210-
stdout = subprocess.check_output(
211-
[
212-
"gh",
213-
"run",
214-
"list",
215-
"--branch",
216-
ref,
217-
"--limit",
218-
"20",
219-
"--json",
220-
"workflowName,url",
221-
],
222-
text=True,
223-
)
224-
225-
try:
226-
runs = json.loads(stdout or "[]")
227-
except json.JSONDecodeError as exc:
228-
raise RuntimeError("Unable to parse workflow run listing.") from exc
229-
230-
for run in runs:
231-
if run.get("workflowName") == "rust-release":
232-
url = run.get("url")
233-
if url:
234-
return url
235-
return None
236-
237-
238211
def resolve_release_workflow(version: str) -> dict:
239212
stdout = subprocess.check_output(
240213
[
@@ -245,12 +218,14 @@ def resolve_release_workflow(version: str) -> dict:
245218
f"rust-v{version}",
246219
"--json",
247220
"workflowName,url,headSha",
221+
"--workflow",
222+
WORKFLOW_NAME,
248223
"--jq",
249-
'first(.[] | select(.workflowName == "rust-release"))',
224+
"first(.[])",
250225
],
251226
text=True,
252227
)
253-
workflow = json.loads(stdout)
228+
workflow = json.loads(stdout or "[]")
254229
if not workflow:
255230
raise RuntimeError(f"Unable to find rust-release workflow for version {version}.")
256231
return workflow

0 commit comments

Comments
 (0)