From cb2f6c2864981457a8d1d203654c58bceabd6853 Mon Sep 17 00:00:00 2001 From: "Eduardo A." <684249+web2solutions@users.noreply.github.com> Date: Sat, 26 Sep 2026 10:24:01 -0300 Subject: [PATCH] fix(release): tolerate changelog-sync race after tagging When sync-changelog lands the chore branch first, reuse its tip instead of failing createCommitOnBranch on a stale expectedHeadOid. Co-authored-by: Cursor --- ci-cd/create-app-release-tag.js | 35 ++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/ci-cd/create-app-release-tag.js b/ci-cd/create-app-release-tag.js index 7f3b96e7..802fe173 100644 --- a/ci-cd/create-app-release-tag.js +++ b/ci-cd/create-app-release-tag.js @@ -788,21 +788,38 @@ function syncChangelogAfterTag({ const contents = fs.readFileSync(path.join(rootDir, 'CHANGELOG.md'), 'utf8'); resetWorktree(rootDir); - ensureBranchAtSha({ + const ensured = ensureBranchAtSha({ repository, branch: changelogBranch, sha: releaseSha, env, cwd: rootDir }); - createSignedCommitOnBranchWithGh({ - repository, - branch: changelogBranch, - expectedHeadOid: releaseSha, - headline: 'chore: synchronize changelog', - additions: [{ path: 'CHANGELOG.md', contents }], - env - }); + + // sync-changelog may race and land the same branch first (app-release run + // 36175725849). Reuse the current tip instead of insisting on releaseSha. + let expectedHeadOid = releaseSha; + if (!ensured.created && ensured.ref && ensured.ref.object && ensured.ref.object.sha) { + expectedHeadOid = ensured.ref.object.sha; + } + + try { + createSignedCommitOnBranchWithGh({ + repository, + branch: changelogBranch, + expectedHeadOid, + headline: 'chore: synchronize changelog', + additions: [{ path: 'CHANGELOG.md', contents }], + env + }); + } catch (error) { + const message = String(error && error.message ? error.message : error); + if (!/but expected|Reference already exists|already exists/i.test(message)) { + throw error; + } + // Tip moved or commit already present — openAndMergeReleasePr reuses the PR. + } + const changelogPr = openAndMergeReleasePr({ branch: changelogBranch, title: 'chore: synchronize changelog',