From 288b700eb45175de03dc801c45c23cf988c9c7fe Mon Sep 17 00:00:00 2001 From: Andrey Avtomonov Date: Wed, 20 May 2026 13:49:38 +0200 Subject: [PATCH] fix(release): don't throw on non-main branches at config-load time knip loads .releaserc.cjs on every PR run, where GITHUB_REF_NAME is the merge ref (e.g. 180/merge). The previous version of releaseBranches threw immediately when the branch wasn't main, which made knip fail to evaluate the config and then mis-flag @semantic-release/exec as an unused dep. semantic-release already refuses to publish when the current branch doesn't match a configured release branch, so the explicit throw was redundant. Drop it (and the unused currentBranch helper) and replace the "rejects releases from non-main" assertion with one that exercises a CI- shaped GITHUB_REF_NAME and confirms the config loads. --- scripts/semantic-release-config.cjs | 9 --------- scripts/semantic-release-config.test.mjs | 11 ++++++----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/scripts/semantic-release-config.cjs b/scripts/semantic-release-config.cjs index 6c424ef8..d1f17bbf 100644 --- a/scripts/semantic-release-config.cjs +++ b/scripts/semantic-release-config.cjs @@ -74,10 +74,6 @@ const releaseNoteTypes = [ { type: 'major', section: 'BREAKING CHANGES', hidden: false }, ]; -function currentBranch(env) { - return env.GITHUB_REF_NAME || env.INPUT_BRANCH || 'main'; -} - function releaseKind(env) { return env.KTX_RELEASE_KIND || env.INPUT_RELEASE_KIND || 'rc'; } @@ -87,13 +83,8 @@ function releaseTag(kind) { } function releaseBranches(env = process.env) { - const branch = currentBranch(env); const kind = releaseKind(env); - if (branch !== 'main') { - throw new Error(`KTX releases must run from main, got ${branch}`); - } - if (kind === 'rc') { return [{ name: 'main', prerelease: 'rc', channel: 'next' }]; } diff --git a/scripts/semantic-release-config.test.mjs b/scripts/semantic-release-config.test.mjs index 2b880d58..be4dcc38 100644 --- a/scripts/semantic-release-config.test.mjs +++ b/scripts/semantic-release-config.test.mjs @@ -64,12 +64,13 @@ describe('semantic-release config', () => { } }); - it('rejects releases from non-main branches', () => { + it('produces a loadable config regardless of GITHUB_REF_NAME', () => { + // Knip and other tooling load .releaserc.cjs on PR runners where + // GITHUB_REF_NAME is the merge ref. semantic-release itself enforces the + // main-only rule by refusing to publish when the current branch does not + // match a configured release branch, so the config must not throw at load. for (const kind of ['rc', 'stable']) { - assert.throws( - () => releaseBranches({ KTX_RELEASE_KIND: kind, GITHUB_REF_NAME: 'feature/release-test' }), - /KTX releases must run from main, got feature\/release-test/, - ); + assert.doesNotThrow(() => releaseBranches({ KTX_RELEASE_KIND: kind, GITHUB_REF_NAME: '180/merge' })); } });