Skip to content

Commit 1f73259

Browse files
committed
fix: avoid stale run ID by verifying trigger timestamp
1 parent 6d3f19a commit 1f73259

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

scripts/create-release.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import tempfile
2222
import subprocess
2323
import threading
24+
import datetime
2425
from pathlib import Path
2526
from concurrent.futures import ThreadPoolExecutor, as_completed
2627

@@ -74,19 +75,26 @@ def bump_version_files(tag):
7475

7576
def trigger_workflow(workflow_file):
7677
"""Trigger a workflow_dispatch run and return its run ID, or None on failure."""
78+
trigger_time = time.time()
7779
r = gh("workflow", "run", workflow_file, "--repo", REPO)
7880
if r.returncode != 0:
7981
log(f" [{workflow_file}] trigger FAILED: {r.stderr.strip()}")
8082
return None
81-
time.sleep(8) # give GitHub a moment to register the run
82-
r2 = gh("run", "list", "--repo", REPO, "--workflow", workflow_file,
83-
"--limit", "1", "--json", "databaseId")
84-
if r2.returncode != 0 or not r2.stdout.strip():
85-
log(f" [{workflow_file}] could not find run after trigger")
86-
return None
87-
run_id = json.loads(r2.stdout)[0]["databaseId"]
88-
log(f" [{workflow_file}] triggered → run {run_id}")
89-
return run_id
83+
# Poll until we see a run whose createdAt is >= our trigger time (up to 60s)
84+
for _ in range(12):
85+
time.sleep(5)
86+
r2 = gh("run", "list", "--repo", REPO, "--workflow", workflow_file,
87+
"--limit", "5", "--json", "databaseId,createdAt")
88+
if r2.returncode != 0 or not r2.stdout.strip():
89+
continue
90+
for run in json.loads(r2.stdout):
91+
created = datetime.datetime.fromisoformat(
92+
run["createdAt"].replace("Z", "+00:00")).timestamp()
93+
if created >= trigger_time - 10: # 10s buffer for clock skew
94+
log(f" [{workflow_file}] triggered → run {run['databaseId']}")
95+
return run["databaseId"]
96+
log(f" [{workflow_file}] could not find new run after trigger")
97+
return None
9098

9199
def wait_for_run(workflow_file, run_id):
92100
"""Poll until the run completes. Returns True on success."""

0 commit comments

Comments
 (0)