Skip to content

fix(publish): make post-publish merge failure non-fatal with resolve strategy retry#778

Merged
BYK merged 2 commits intomasterfrom
fix/non-fatal-post-publish-merge
Mar 19, 2026
Merged

fix(publish): make post-publish merge failure non-fatal with resolve strategy retry#778
BYK merged 2 commits intomasterfrom
fix/non-fatal-post-publish-merge

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 18, 2026

Problem

When all publish targets succeed but the subsequent merge of the release branch back into the default branch fails (e.g., due to a CHANGELOG.md conflict), the entire craft publish command exits with code 1 — even though all irreversible publishing operations completed successfully.

This caused the publish workflow to report failure, leave the publish issue open, skip the post-release command, and leave the release branch unmerged and undeleted.

Observed in: getsentry/publish#7519 ([email protected])

Fix

Part 1 — Retry with resolve strategy: Breaks the chained pull().merge().push() into separate calls. When the default merge strategy (ort) fails, the function aborts the merge and retries with -s resolve, which uses a simpler 3-way merge algorithm that handles criss-cross ambiguities differently.

Part 2 — Non-fatal error handling: If both strategies fail, the error is caught in publishMain(), reported to Sentry via captureException, and a warning with manual resolution instructions is logged — but the command still exits successfully since all targets published. State file cleanup and the post-release command always run regardless of merge outcome.

Test plan

  • 7 new tests for handleReleaseBranch covering: default merge success, resolve retry on conflict, abort failure tolerance, both-strategies-fail propagation, branch deletion, keepBranch, and default branch resolution
  • All existing tests pass
  • Lint clean (only pre-existing warnings)

…strategy retry

When all publish targets succeed but the subsequent merge of the release
branch back into the default branch fails (e.g., due to a CHANGELOG.md
conflict), the entire publish command would exit with code 1 — even
though all irreversible publishing operations completed successfully.

This caused the publish workflow to report failure, leave the publish
issue open, skip the post-release command, and leave the release branch
unmerged.

Changes:
- Break the chained pull().merge().push() into separate calls so merge
  failures can be caught and retried independently
- On merge failure with the default strategy (ort), abort and retry
  with -s resolve which handles criss-cross merge ambiguities
  differently and often succeeds where ort fails
- If both strategies fail, catch the error in publishMain(), report to
  Sentry via captureException, log a warning with manual resolution
  instructions, but still exit successfully since all targets published
- State file cleanup and post-release command now always run regardless
  of merge outcome
- Export handleReleaseBranch for testability

Fixes: getsentry/publish#7519
@BYK BYK marked this pull request as ready for review March 18, 2026 17:43
@BYK BYK requested a review from itaybre March 18, 2026 17:43
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Copy link

@itaybre itaybre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the manual steps

- Wrap git pull --rebase in try/catch with git rebase --abort cleanup
  so a failed rebase doesn't leave the repo in an active rebase state
- Wrap resolve strategy retry in try/catch with git merge --abort
  so a failed resolve merge also leaves the repo clean
- Replace hardcoded 'origin' with argv.remote in manual resolution
  instructions (supports non-default remotes)
- Add test for rebase abort on pull failure
- Update both-strategies-fail test to verify second merge --abort
@BYK BYK merged commit 352ba0c into master Mar 19, 2026
18 checks passed
@BYK BYK deleted the fix/non-fatal-post-publish-merge branch March 19, 2026 21:08
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