Skip to content

Commit 848fe45

Browse files
avalleteclaude
andauthored
chore(ci): strip GitHub Actions env vars in backfill-release-notes (#5324)
Fix the backfill-release-notes script to correctly detect the git branch when running semantic-release in dry-run mode. The script was passing the full process environment to semantic-release, which includes GitHub Actions detection variables (GITHUB_REF, GITHUB_ACTIONS, etc.). The semantic-release library uses env-ci to detect the current branch, and env-ci prioritizes these CI environment variables over the actual git HEAD state. This caused env-ci to report the wrong branch when backfilling from a workflow that ran on a different branch than the current clone's HEAD, leading to semantic-release errors about local branches being behind remote. **Key changes:** - Create a filtered child environment that strips GitHub Actions detection variables (GITHUB_ACTIONS, GITHUB_REF, GITHUB_REF_NAME, GITHUB_HEAD_REF, GITHUB_BASE_REF, GITHUB_EVENT_NAME, CI) - Pass the filtered environment to semantic-release instead of the full process environment - This allows env-ci to fall back to reading the branch from git HEAD in the clone, which is the correct source of truth for the backfill operation https://claude.ai/code/session_01QQsjHNdZTJHhLWr2FYSjhe Co-authored-by: Claude <noreply@anthropic.com>
1 parent bc0600d commit 848fe45

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

apps/cli/scripts/backfill-release-notes.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,32 @@ try {
175175
console.error(`==> Re-staged on ${branch} @ ${sha} (without tag ${tag})`);
176176
console.error(`==> Running semantic-release --dry-run`);
177177

178+
// semantic-release uses env-ci to detect the current branch, which reads
179+
// GITHUB_REF (and friends) from the GitHub Actions environment. `noCi: true`
180+
// only bypasses the "not in CI" guard - it does not stop env-ci from
181+
// resolving the branch from CI vars. When backfilling v2.100.1 from a
182+
// workflow that ran on develop, env-ci returns "develop" even though the
183+
// clone's HEAD points at main, and semantic-release then complains that
184+
// local develop is behind remote. Strip the GitHub Actions detection vars
185+
// so env-ci falls back to reading the branch from git HEAD in the clone.
186+
const childEnv = { ...process.env };
187+
for (const key of [
188+
"GITHUB_ACTIONS",
189+
"GITHUB_REF",
190+
"GITHUB_REF_NAME",
191+
"GITHUB_HEAD_REF",
192+
"GITHUB_BASE_REF",
193+
"GITHUB_EVENT_NAME",
194+
"CI",
195+
]) {
196+
delete childEnv[key];
197+
}
198+
178199
const result = await semanticRelease(
179200
{ dryRun: true, noCi: true, repositoryUrl: repoUrl },
180201
{
181202
cwd: path.join(clone, "apps/cli"),
182-
env: process.env,
203+
env: childEnv,
183204
stdout: process.stderr,
184205
stderr: process.stderr,
185206
},

0 commit comments

Comments
 (0)