|
21 | 21 | import tempfile |
22 | 22 | import subprocess |
23 | 23 | import threading |
| 24 | +import datetime |
24 | 25 | from pathlib import Path |
25 | 26 | from concurrent.futures import ThreadPoolExecutor, as_completed |
26 | 27 |
|
@@ -74,19 +75,26 @@ def bump_version_files(tag): |
74 | 75 |
|
75 | 76 | def trigger_workflow(workflow_file): |
76 | 77 | """Trigger a workflow_dispatch run and return its run ID, or None on failure.""" |
| 78 | + trigger_time = time.time() |
77 | 79 | r = gh("workflow", "run", workflow_file, "--repo", REPO) |
78 | 80 | if r.returncode != 0: |
79 | 81 | log(f" [{workflow_file}] trigger FAILED: {r.stderr.strip()}") |
80 | 82 | 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 |
90 | 98 |
|
91 | 99 | def wait_for_run(workflow_file, run_id): |
92 | 100 | """Poll until the run completes. Returns True on success.""" |
|
0 commit comments