Repository navigation
fix(publish): Resolve merge conflicts caused only by the version bump - #964
Conversation
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>
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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; |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 71da3c5. Configure here.
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 -->
) 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>


The toolkit
cli/0.48.0publish (job log) shipped every target but couldn't mergerelease/cli/0.48.0back. The release branch changedversion: 0.48.0-dev.0toversion: 0.48.0inreferences/init.md, andmainchanged thedescription:line right below it. Bothortandresolvereport that as a conflict, so the branch stays unmerged andpostReleaseBumpis skipped too.With
postReleaseBump, this will happen again any time a versioned file changes near its version line betweenprepareandpublish.What changed
When the
resolvestrategy fails, Craft now tries to resolve the conflict itself before it aborts:git merge-file --diff3, using large markers so that file content can't look like a marker.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.MergeConflictErrorpath, unchanged. It also refuses when the target branch changed the version line itself.handleReleaseBranchgets an optionalreleaseVersion, andpublishMainpassesnewVersionto it. The release-workflow docs describe the new behavior.Verification
versionConflicts.test.ts, plus two real-git tests inpublish.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 withMergeConflictError.mainat4f1162a8, merged withrelease/cli/0.48.0at283b5557. The resolver fixedinit.mdtoversion: 0.48.0with the new description frommain.pnpm lintandtscpass.pnpm testhas 24 failures inprepare-dry-run.e2eand one other e2e file, and they fail the same way onmasterin my sandbox.via @BYK.
--
View Session in Sentry