From 208f73c98278d662e63dcc8784b83de19b7294c3 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 20 May 2026 16:00:39 +0000 Subject: [PATCH] fix(ci): strip GitHub Actions env vars in backfill-release-notes semantic-release uses env-ci to detect the current branch, which reads GITHUB_REF from the GitHub Actions environment. The `noCi: true` option only bypasses the "not in CI" guard - it does not stop env-ci from resolving the branch from CI vars. When backfilling a stable tag like v2.100.1 from a workflow that runs on develop, env-ci returned "develop" even though the clone's HEAD was checked out on main, so semantic-release ran with branch=develop and bailed with "local branch develop is behind the remote one". Strip the GitHub Actions detection vars before invoking semantic-release so env-ci falls back to reading HEAD from the clone, which the script has already positioned on the correct branch for the tag. --- apps/cli/scripts/backfill-release-notes.ts | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/cli/scripts/backfill-release-notes.ts b/apps/cli/scripts/backfill-release-notes.ts index e40c1d06e..139db13fa 100644 --- a/apps/cli/scripts/backfill-release-notes.ts +++ b/apps/cli/scripts/backfill-release-notes.ts @@ -175,11 +175,32 @@ try { console.error(`==> Re-staged on ${branch} @ ${sha} (without tag ${tag})`); console.error(`==> Running semantic-release --dry-run`); + // semantic-release uses env-ci to detect the current branch, which reads + // GITHUB_REF (and friends) from the GitHub Actions environment. `noCi: true` + // only bypasses the "not in CI" guard - it does not stop env-ci from + // resolving the branch from CI vars. When backfilling v2.100.1 from a + // workflow that ran on develop, env-ci returns "develop" even though the + // clone's HEAD points at main, and semantic-release then complains that + // local develop is behind remote. Strip the GitHub Actions detection vars + // so env-ci falls back to reading the branch from git HEAD in the clone. + const childEnv = { ...process.env }; + for (const key of [ + "GITHUB_ACTIONS", + "GITHUB_REF", + "GITHUB_REF_NAME", + "GITHUB_HEAD_REF", + "GITHUB_BASE_REF", + "GITHUB_EVENT_NAME", + "CI", + ]) { + delete childEnv[key]; + } + const result = await semanticRelease( { dryRun: true, noCi: true, repositoryUrl: repoUrl }, { cwd: path.join(clone, "apps/cli"), - env: process.env, + env: childEnv, stdout: process.stderr, stderr: process.stderr, },