Skip to content

fix(publish): Resolve merge conflicts caused only by the version bump - #964

Merged
BYK merged 1 commit into
masterfrom
byk/fix/publish-version-bump-conflicts
Nov 5, 2026
Merged

BYK merged 1 commit into
masterfrom
byk/fix/publish-version-bump-conflicts

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

The toolkit cli/0.48.0 publish (job log) shipped every target but couldn't merge release/cli/0.48.0 back. The release branch changed version: 0.48.0-dev.0 to version: 0.48.0 in references/init.md, and main changed the description: line right below it. Both ort and resolve report that as a conflict, so the branch stays unmerged and postReleaseBump is skipped too.

With postReleaseBump, this will happen again any time a versioned file changes near its version line between prepare and publish.

What changed

When the resolve strategy fails, Craft now tries to resolve the conflict itself before it aborts:

  • It merges each conflicted file again with git merge-file --diff3, using large markers so that file content can't look like a marker.
  • It resolves a hunk only when the release side (theirs) matches the base except for version tokens that became the released version. Craft then keeps the target branch's lines (ours) and applies the same version replacement to them.
  • It writes and commits nothing unless every conflicted file can be resolved this way. Hotfixes on the release branch, new changelog sections, add/delete conflicts, binary files and non-UTF-8 files all go to the existing MergeConflictError path, unchanged. It also refuses when the target branch changed the version line itself.

handleReleaseBranch gets an optional releaseVersion, and publishMain passes newVersion to it. The release-workflow docs describe the new behavior.

Verification

  • New unit tests in versionConflicts.test.ts, plus two real-git tests in publish.test.ts: one where only the version conflicts, so the merge is pushed and the branch deleted, and one with a hotfix next to the version line, which aborts with MergeConflictError.
  • I replayed the real toolkit case locally: main at 4f1162a8, merged with release/cli/0.48.0 at 283b5557. The resolver fixed init.md to version: 0.48.0 with the new description from main.
  • pnpm lint and tsc pass. pnpm test has 24 failures in prepare-dry-run.e2e and one other e2e file, and they fail the same way on master in my sandbox.

via @BYK.

--

View Session in Sentry

When the merge target changed lines next to the version strings the
release branch bumped, both merge strategies conflict and the release
branch is left unmerged, which also skips the post-release bump.

After the resolve strategy fails, re-merge each conflicted file with
git merge-file --diff3 and resolve a hunk when the release side only
replaced version tokens with the released version: keep the target's
lines and apply the same replacement to them. Any other conflict still
aborts the merge as before.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-11-05 20:41 UTC

@BYK
BYK merged commit 291a934 into master Nov 5, 2026
29 checks passed
@BYK
BYK deleted the byk/fix/publish-version-bump-conflicts branch November 5, 2026 20:40
@sentry-junior sentry-junior Bot changed the title fix(publish): Resolve merge conflicts caused only by the version bump fix(publish): Resolve version-bump merge conflicts and fail on other merge failures Nov 5, 2026
@sentry-junior sentry-junior Bot changed the title fix(publish): Resolve version-bump merge conflicts and fail on other merge failures fix(publish): Resolve merge conflicts caused only by the version bump Nov 5, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

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 1 potential issue.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 71da3c5. Configure here.

}
resolved = resolved.replace(oldVersionRegExp, version);
}
return resolved;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hunk-wide version replace is too broad

Medium Severity

resolveVersionBumpHunk collects the old version tokens from base versus theirs, then globally replaces every matching token in ours. Occurrences the release side left unchanged can sit in the same hunk when they fall between the version line and a nearby target-branch edit, so those tokens get rewritten too and the auto-merge can push the wrong values.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 71da3c5. Configure here.

BYK added a commit to getsentry/toolkit that referenced this pull request Nov 5, 2026
This finishes the CLI 0.48.0 release. Every publish target shipped, but
Craft couldn't merge the release branch back into `main` ([job
log](https://github.com/getsentry/publish/actions/runs/42102069927/job/127507152523)),
so the post-release bump never ran either.

**Why the merge failed:** `release: 0.48.0` (283b555) changed `version:
0.48.0-dev.0` to `version: 0.48.0` in `references/init.md`. #1856
changed the `description:` line right below it on `main`. The fix in
Craft is getsentry/craft#964.

**This PR**
1. Merges `release/cli/0.48.0` into `main`. That brings in the 0.48.0
`CHANGELOG.md` section and the release versions. For `init.md`, it keeps
the new description from `main` together with `version: 0.48.0`. I
resolved the conflict with the resolver from getsentry/craft#964.
2. Bumps to the next development version the same way Craft's
`postReleaseBump` does: the npm bump plus `versioning.files` from
`.craft.yml`.
- `packages/cli/package.json` and `packages/mcp-server/package.json` →
`0.49.0-dev.0`
   - Skill frontmatter (`SKILL.md`, `references/*.md`) → `0.49.0-dev.0`
   - `.claude-plugin/plugin.json` → `0.49.0` (`stripPrerelease`)

Squash merging is fine: the `cli@0.48.0` tag already points at the
release commit. Once this lands, `release/cli/0.48.0` can be deleted.

#skip-changelog

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A2b52a6f3270e30b7c2e844d3 -->

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A2b52a6f3270e30b7c2e844d3/?project=4510944073809921)

<!-- junior-session-footer:end -->
BYK added a commit that referenced this pull request Nov 5, 2026
)

Follow-up to #964. When Craft can't merge the release branch back, it
now fails the publish instead of logging a warning. That way the failure
shows up in getsentry/publish and can be retried or recovered from
there.

The toolkit `cli/0.48.0` publish ([job
log](https://github.com/getsentry/publish/actions/runs/42102069927/job/127507152523))
is the motivating case. Every target shipped, but the merge hit a
conflict. Craft warned and reported success, so the run was green while
the release branch stayed unmerged and `postReleaseBump` was skipped.
Someone had to read the logs to notice. getsentry/toolkit#2028 cleans up
that release.

**What changed**

- When `handleReleaseBranch` fails with a merge conflict, a push
failure, or any other error, `craft publish` now throws
`ReleaseBranchMergeError`. The error says every target published and
lists the conflicting files and the diff. It also says how to recover:
- merge the target branch into the release branch and push it, so the
retry merges the new head, or
- merge the release branch into the target branch yourself with a merge
commit (not a squash), so the retry is a no-op merge plus cleanup.
- The publish state file is kept, so the retry skips the published
targets and only merges. In getsentry/publish, the issue checkboxes
already do the same, so re-adding `accepted` retries only the merge.
- The post-release bump and the post-release command are skipped. They
run on the successful retry.
- `BranchCleanupError` stays a warning, because the merge was already
pushed and a retry can't help.
- Sentry reporting now goes through the global error handler, instead of
a `captureException` call in the merge path.

This reverses the earlier decision that the merge is non-blocking
housekeeping. I updated `.lore.md` and the release-workflow docs to
match.

**Verification**

- New `publishMain` tests: a merge conflict and a push failure both
reject with `ReleaseBranchMergeError` and keep the state file, and a
failed merge skips the bump. The existing cleanup-failure test still
passes as a warning.
- `pnpm lint` and `tsc` pass, and the `src/commands` and resolver tests
pass (91 tests). In the full `pnpm test`, the only failures are the same
e2e failures (24 in `prepare-dry-run.e2e` and one other file) that I
also see on `master` in my sandbox.

**Not changed:** the getsentry/publish failure comment still says "Bad
branch? You can delete with ease and start over". For a merge failure
that's the wrong advice: deleting the branch makes the retry fail with
"Could not find the release branch".

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A2b52a6f3270e30b7c2e844d3 -->

--

[View Session in
Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A2b52a6f3270e30b7c2e844d3/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
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.

1 participant