Skip to content

Commit ef0a8b2

Browse files
committed
ci_scripts/check_versions.py: gracefully handle existence of upgrade PRs
The workflow currently fails every night because of a backlog of version upgrade PRs already being open from previous runs. Improve check_versions.py script so that if it can't open these PRs for versions RISE doesn't yet build, then it finishes gracefully. Do this by trying to confirm the existence of a PR for the given version(s), then warning the maintainer that they should check for them manually if they can't be detected automatically. AI-Generated: Uses Claude Sonnet 5 Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
1 parent 206a979 commit ef0a8b2

1 file changed

Lines changed: 50 additions & 5 deletions

File tree

ci_scripts/check_versions.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,36 @@ def extract_pr_url(stdout: str) -> Optional[str]:
160160
return None
161161

162162

163+
def find_open_pr_for_branch(branch: str) -> Optional[str]:
164+
"""Return the URL of an open PR with the given head branch, if any."""
165+
try:
166+
result = subprocess.run([
167+
"gh", "pr", "list",
168+
"--repo", REPO,
169+
"--head", branch,
170+
"--state", "open",
171+
"--json", "url",
172+
"--jq", ".[0].url",
173+
], capture_output=True, text=True, timeout=30)
174+
175+
if result.returncode != 0:
176+
return None
177+
178+
return result.stdout.strip() or None
179+
180+
except (subprocess.TimeoutExpired, subprocess.SubprocessError):
181+
return None
182+
183+
163184
def create_deprecation_pr(package: str, reason: str) -> Optional[str]:
164185
"""Create a pull request to deprecate a package."""
186+
branch = f"github-actions/deprecate-{package}"
187+
188+
existing_pr = find_open_pr_for_branch(branch)
189+
if existing_pr:
190+
print(f" [=] PR already open for {package}: {existing_pr}")
191+
return existing_pr
192+
165193
try:
166194
git_run("fetch", "origin")
167195
git_run("switch", "main")
@@ -185,8 +213,6 @@ def create_deprecation_pr(package: str, reason: str) -> Optional[str]:
185213
else:
186214
print(f" [!] No upstream issue found for {package}")
187215

188-
branch = f"github-actions/deprecate-{package}"
189-
190216
configure_git_identity()
191217
git_run("switch", "-c", branch)
192218

@@ -238,7 +264,13 @@ def create_deprecation_pr(package: str, reason: str) -> Optional[str]:
238264
return extract_pr_url(result.stdout) or f"PR created for {package} (URL not found in output)"
239265

240266
except subprocess.CalledProcessError as e:
267+
existing_pr = find_open_pr_for_branch(branch)
268+
if existing_pr:
269+
print(f" [=] PR already open for {package}: {existing_pr}")
270+
return existing_pr
241271
print(f" [X] Error creating PR for {package}: {e.stderr or e}")
272+
print(f" [?] Could not confirm whether a PR already exists for {package} "
273+
"— please check open PRs manually")
242274
return None
243275
except Exception as e:
244276
print(f" [X] Unexpected error creating PR for {package}: {e}")
@@ -361,14 +393,19 @@ def create_upgrade_pr(package: str, package_info: Dict, new_versions: List[str])
361393
return None
362394

363395
latest_version = new_versions[-1]
396+
branch = f"github-actions/upgrade-{package}-{latest_version}"
397+
398+
existing_pr = find_open_pr_for_branch(branch)
399+
if existing_pr:
400+
print(f" [=] PR already open for {package}: {existing_pr}")
401+
return existing_pr
364402

365403
try:
366404
configure_git_identity()
367405

368406
git_run("fetch", "origin")
369407
git_run("switch", "main")
370408

371-
branch = f"github-actions/upgrade-{package}-{latest_version}"
372409
git_run("switch", "-c", branch)
373410

374411
pypi_package_url = get_pypi_package_url(package_info)
@@ -467,7 +504,13 @@ def create_upgrade_pr(package: str, package_info: Dict, new_versions: List[str])
467504
return pr_url
468505

469506
except subprocess.CalledProcessError as e:
507+
existing_pr = find_open_pr_for_branch(branch)
508+
if existing_pr:
509+
print(f" [=] PR already open for {package}: {existing_pr}")
510+
return existing_pr
470511
print(f" [X] Error creating upgrade PR for {package}: {e.stderr or e}")
512+
print(f" [?] Could not confirm whether a PR already exists for {package} "
513+
"— please check open PRs manually")
471514
return None
472515
except Exception as e:
473516
print(f" [X] Unexpected error creating upgrade PR for {package}: {e}")
@@ -651,9 +694,11 @@ def main():
651694
if r["status"] in ("need_upgrade", "can_deprecate") and r.get("pr_url") is None
652695
]
653696
if pr_failures:
654-
print(f"\n[X] PR creation failed for {len(pr_failures)} package(s): "
697+
print(f"\n[?] Could not create (or confirm an existing) PR for "
698+
f"{len(pr_failures)} package(s): "
655699
+ ", ".join(r["package"] for r in pr_failures))
656-
sys.exit(1)
700+
print(" Please review open PRs to check whether one already exists "
701+
"for these packages.")
657702

658703

659704
if __name__ == "__main__":

0 commit comments

Comments
 (0)