From b4a8d61ff23c7a65c5aa3bc42af57e21628dd19d Mon Sep 17 00:00:00 2001 From: Jon Church Date: Fri, 22 May 2026 23:14:58 -0400 Subject: [PATCH] fix: skip pr job when pkg.version differs from latest tag Replaces the racey isReleaseMergeCommit API lookup with a local check. Refs #15 --- scripts/update-changelog.ts | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/scripts/update-changelog.ts b/scripts/update-changelog.ts index cefc1c4..155c243 100644 --- a/scripts/update-changelog.ts +++ b/scripts/update-changelog.ts @@ -278,34 +278,27 @@ async function getContributors ( return out } -async function isReleaseMergeCommit ( - repo: { owner: string, repo: string }, - sha: string, -): Promise { - // We don't want to update the changelog when a `release/vX.Y.Z` PR is merged. - try { - const prs = await gh>( - `/repos/${repo.owner}/${repo.repo}/commits/${sha}/pulls`, - ) - return prs.some(pr => pr.merged_at && pr.head.ref.startsWith('release/v')) - } catch { - return false - } -} - async function main () { const dryRun = Boolean(process.env.DRY_RUN) const repo = getRepo() const baseBranch = getCurrentBranch() - const headSha = git('rev-parse', 'HEAD') - if (await isReleaseMergeCommit(repo, headSha)) { - console.log(`HEAD (${headSha.slice(0, 7)}) is the merge of a release PR; skipping.`) + const latestTag = getLatestTag() + + const pkgPath = resolve(process.cwd(), 'package.json') + const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) + + // Skip when `package.json` is out of sync with the latest tag. This is true + // in the window between a release PR's merge updating `pkg.version` on the + // base branch and the parallel `release` job pushing the matching tag — the + // exact transitional state where we don't want to open a new release PR. + // The symmetric case (tag already at HEAD) is handled by the `!commits.length` + // early-exit below. + if (latestTag && pkg.version !== latestTag.name.replace(/^v/, '')) { + console.log(`pkg.version ${pkg.version} differs from latest tag ${latestTag.name}; skipping (release likely in flight).`) return } - const latestTag = getLatestTag() - const commits = getCommitsSince(latestTag).filter( c => KNOWN_TYPES.has(c.type) && !(c.type === 'chore' && c.scope === 'deps'), ) @@ -315,8 +308,6 @@ async function main () { return } - const pkgPath = resolve(process.cwd(), 'package.json') - const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) const bump = determineBump(commits) const newVersion = incVersion(pkg.version, bump) const releaseBranch = `release/v${newVersion}`