Skip to content

Fail the action when a backport fails, retry pushes, and report git errors - #21

Merged
DaedalusG merged 1 commit into
mainfrom
wg/fail-on-backport-error
Nov 18, 2026
Merged

DaedalusG merged 1 commit into
mainfrom
wg/fail-on-backport-error

Conversation

@DaedalusG

@DaedalusG DaedalusG commented Nov 17, 2026 •

Copy link
Copy Markdown

Problem

When a backport to a release branch fails, the action posts a failure comment and labels on the PR, but the job still succeeds. The error for each branch is caught in backport() and never reaches setFailed. In the last 200 Backport runs in sourcegraph/sourcegraph, none failed, even though at least 15 PRs got failed-backport-to-* labels in that time.

Example: run 44198843437 for sourcegraph/sourcegraph#19164 passed. Its push had been rejected with Unable to determine if workflow can be created or updated due to timeout; workflows scope may be required., and the PR comment only said The process '/usr/bin/git' failed with exit code 1.

Changes

  • Fail the action when any backport fails. backport() now returns the branches that failed. After setting created_pull_requests, index.ts calls setFailed if any branch failed. The failure comment and labels are still posted first, so a failure on one branch doesn't stop the others.
  • Retry git push. The push is tried up to 3 times, waiting 10 seconds and then 20 seconds, with a warning each time. This covers rejections that pass on a second try. It does not fix the 8.2.x timeouts above: those fail every time, and the fix for them is adding the workflow scope to the token.
  • Report git's error output. The git helper captures stderr and puts it in the error. The PR comment now shows, for example, the ! [remote rejected] ... (reason) line or error: could not apply ... instead of only the exit code.
  • Bump the version to 2.0.13 so that merging publishes a release. sourcegraph/sourcegraph then needs its pin in .github/workflows/backport.yml updated.

Test plan

yarn build and yarn xo pass. I ran the built dist/index.js end to end with a local bare repo as the remote (a pre-receive hook rejects pushes) and a local HTTP server standing in for the GitHub API:

Scenario v2.0.12 (current pin) This branch
Push always rejected exit 0, comment shows only the exit code 3 push attempts, exit 1, comment includes the remote rejected output
Push rejected once n/a 1 retry, push succeeds, backport PR created, exit 0
Cherry-pick conflict n/a exit 1, comment includes error: could not apply ...

In all failure cases the comment and the release-blocker and failed-backport-to-* labels are still posted.

…rrors

- Mark the action as failed when any backport branch fails, after posting
  the PR comment and labels, so the workflow run no longer shows as passed.
- Retry git push up to 3 times, since GitHub sometimes rejects pushes
  transiently (for example when its workflow-file check times out).
- Include git's stderr in the error, so the PR comment says why git failed
  instead of only the exit code.
- Bump version to 2.0.13 so merging publishes a release.

Amp-Thread-ID: https://ampcode.com/threads/T-5c922310-4117-4bfd-8e10-34ae4aaca078
@DaedalusG
DaedalusG requested a review from a team November 18, 2026 04:48
@DaedalusG
DaedalusG marked this pull request as ready for review November 18, 2026 04:48
@DaedalusG
DaedalusG enabled auto-merge (squash) November 18, 2026 06:00
@DaedalusG
DaedalusG merged commit 1e755a2 into main Nov 18, 2026
1 check passed
@DaedalusG
DaedalusG deleted the wg/fail-on-backport-error branch November 18, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants