mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-22 08:38:08 +02:00
chore: add semantic release workflow
This commit is contained in:
parent
5073a76a5b
commit
a11f7a06ae
18 changed files with 2822 additions and 56 deletions
53
scripts/semantic-release-config.test.mjs
Normal file
53
scripts/semantic-release-config.test.mjs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { createRequire } from 'node:module';
|
||||
import { describe, it } from 'node:test';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { createReleaseConfig, releaseBranches, releaseKind, releaseTag } = require('./semantic-release-config.cjs');
|
||||
|
||||
function releaseExecOptions(config) {
|
||||
return config.plugins.find((plugin) => Array.isArray(plugin) && plugin[0] === '@semantic-release/exec' && plugin[1].prepareCmd)[1];
|
||||
}
|
||||
|
||||
describe('semantic-release config', () => {
|
||||
it('configures manual rc releases on the selected branch with next channel', () => {
|
||||
assert.equal(releaseKind({ KTX_RELEASE_KIND: 'rc' }), 'rc');
|
||||
assert.equal(releaseTag('rc'), 'next');
|
||||
assert.deepEqual(releaseBranches({ KTX_RELEASE_KIND: 'rc', GITHUB_REF_NAME: 'release-candidate' }), [
|
||||
{ name: 'release-candidate', prerelease: 'rc', channel: 'next' },
|
||||
]);
|
||||
|
||||
const config = createReleaseConfig({ KTX_RELEASE_KIND: 'rc', GITHUB_REF_NAME: 'release-candidate' });
|
||||
assert.match(
|
||||
releaseExecOptions(config).prepareCmd,
|
||||
/update-public-release-version\.mjs "\$\{nextRelease\.version\}" "next"/,
|
||||
);
|
||||
});
|
||||
|
||||
it('configures stable releases only from main with latest tag', () => {
|
||||
assert.equal(releaseKind({ KTX_RELEASE_KIND: 'stable' }), 'stable');
|
||||
assert.equal(releaseTag('stable'), 'latest');
|
||||
assert.deepEqual(releaseBranches({ KTX_RELEASE_KIND: 'stable', GITHUB_REF_NAME: 'main' }), ['main']);
|
||||
|
||||
const config = createReleaseConfig({ KTX_RELEASE_KIND: 'stable', GITHUB_REF_NAME: 'main' });
|
||||
assert.match(
|
||||
releaseExecOptions(config).prepareCmd,
|
||||
/update-public-release-version\.mjs "\$\{nextRelease\.version\}" "latest"/,
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects stable releases from non-main branches', () => {
|
||||
assert.throws(
|
||||
() => releaseBranches({ KTX_RELEASE_KIND: 'stable', GITHUB_REF_NAME: 'feature/release-test' }),
|
||||
/Stable KTX releases must run from main, got feature\/release-test/,
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps the force-release patch escape hatch', () => {
|
||||
const config = createReleaseConfig({ KTX_RELEASE_KIND: 'rc', GITHUB_REF_NAME: 'main' });
|
||||
const analyzeExec = config.plugins.find(
|
||||
(plugin) => Array.isArray(plugin) && plugin[0] === '@semantic-release/exec' && plugin[1].analyzeCommitsCmd,
|
||||
);
|
||||
assert.match(analyzeExec[1].analyzeCommitsCmd, /FORCE_RELEASE === 'true' \? 'patch' : ''/);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue