Handle closed PR checkout failures as warnings instead of errors#14528
Handle closed PR checkout failures as warnings instead of errors#14528
Conversation
- Detect closed PR state before checkout - Treat checkout failures on closed PRs as warnings, not errors - Set checkout_pr_success to true for closed PRs - Add comprehensive tests for closed PR scenarios - Ensure open PRs still fail on checkout errors Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates the PR-branch checkout GitHub Action script to avoid failing workflows when processing events on closed pull requests whose branches may have been deleted, while preserving failure behavior for open PRs.
Changes:
- Detects
pullRequest.state === "closed"and treats checkout failures as warnings (step continues). - Adds step-summary + grouped warning logs for closed-PR checkout failures.
- Extends unit tests to cover closed-PR warning behavior vs open-PR error behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
actions/setup/js/checkout_pr_branch.cjs |
Adds closed-PR detection and warning-only handling for checkout failures, including summary output. |
actions/setup/js/checkout_pr_branch.test.cjs |
Adds test coverage for closed-PR checkout failures being warnings and open-PR failures remaining errors. |
scratchpad/pr-checkout-logic-explained.md |
Documents the new closed-PR behavior and expected logs/tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| **This is not an error** - workflows targeting closed PRs will continue normally.`; | ||
|
|
||
| await core.summary.addRaw(warningMessage).write(); |
There was a problem hiding this comment.
In the closed-PR warning path, core.summary.addRaw(...).write() is awaited without any protection. If writing the summary throws (filesystem issues, runner limitations, etc.), the script will throw and the step can still fail—negating the intent to treat closed-PR checkout failures as warnings. Consider wrapping the summary write in a try/catch (logging a warning on failure) so the closed-PR path cannot error out.
| await core.summary.addRaw(warningMessage).write(); | |
| try { | |
| await core.summary.addRaw(warningMessage).write(); | |
| } catch (summaryError) { | |
| core.warning(`Failed to write closed PR summary: ${getErrorMessage(summaryError)}`); | |
| } |
When workflows process events on closed PRs (e.g., comments), checkout fails if the branch was deleted. This causes the entire workflow step to fail, preventing any further processing.
Changes
pullRequest.state === "closed"checkout_pr_branch.cjsto differentiate between closed and open PRscheckout_pr_success=true, continue workflowBehavior
Closed PR with deleted branch:
Step output:
checkout_pr_success: "true"(workflow continues)Open PR with checkout failure:
Step output:
checkout_pr_success: "false"(workflow fails as before)Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.