mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
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.
This commit is contained in:
parent
66b674f73a
commit
288b700eb4
2 changed files with 6 additions and 14 deletions
|
|
@ -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' }];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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' }));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue