mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-07 07:55:13 +02:00
fix: recover snapshots and branch rc tags (#185)
This commit is contained in:
parent
c24e07a115
commit
2667952aa9
6 changed files with 110 additions and 10 deletions
|
|
@ -9,6 +9,7 @@ describe('release workflow', () => {
|
|||
assert.match(workflow, /^name: KTX Release$/m);
|
||||
assert.match(workflow, /^ workflow_dispatch:$/m);
|
||||
assert.match(workflow, /release_kind:/);
|
||||
assert.match(workflow, /Branch rc releases publish to branch-specific npm tags/);
|
||||
assert.match(workflow, /release_kind:[\s\S]*?default: "stable"/);
|
||||
assert.match(workflow, /options:\n - stable\n - rc/);
|
||||
assert.match(workflow, /force_release:/);
|
||||
|
|
|
|||
|
|
@ -78,15 +78,43 @@ function releaseKind(env) {
|
|||
return env.KTX_RELEASE_KIND || env.INPUT_RELEASE_KIND || 'rc';
|
||||
}
|
||||
|
||||
function releaseTag(kind) {
|
||||
return kind === 'rc' ? 'next' : 'latest';
|
||||
function currentBranchName(env = process.env) {
|
||||
return env.GITHUB_REF_NAME || env.INPUT_BRANCH || 'main';
|
||||
}
|
||||
|
||||
function branchPrereleaseId(branchName) {
|
||||
return (
|
||||
branchName
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '') || 'branch'
|
||||
);
|
||||
}
|
||||
|
||||
function releaseTag(kind, env = process.env) {
|
||||
if (kind !== 'rc') {
|
||||
return 'latest';
|
||||
}
|
||||
|
||||
const branchName = currentBranchName(env);
|
||||
if (branchName === 'main') {
|
||||
return 'next';
|
||||
}
|
||||
|
||||
return `branch-${branchPrereleaseId(branchName)}`;
|
||||
}
|
||||
|
||||
function releaseBranches(env = process.env) {
|
||||
const kind = releaseKind(env);
|
||||
|
||||
if (kind === 'rc') {
|
||||
return [{ name: 'main', prerelease: 'rc', channel: 'next' }];
|
||||
const branches = [{ name: 'main', prerelease: 'rc', channel: 'next' }];
|
||||
const branchName = currentBranchName(env);
|
||||
if (branchName !== 'main') {
|
||||
const prerelease = branchPrereleaseId(branchName);
|
||||
branches.push({ name: branchName, prerelease, channel: `branch-${prerelease}` });
|
||||
}
|
||||
return branches;
|
||||
}
|
||||
|
||||
if (kind === 'stable') {
|
||||
|
|
@ -98,7 +126,7 @@ function releaseBranches(env = process.env) {
|
|||
|
||||
function createReleaseConfig(env = process.env) {
|
||||
const kind = releaseKind(env);
|
||||
const tag = releaseTag(kind);
|
||||
const tag = releaseTag(kind, env);
|
||||
|
||||
return {
|
||||
tagFormat: 'v${version}',
|
||||
|
|
|
|||
|
|
@ -39,6 +39,24 @@ describe('semantic-release config', () => {
|
|||
assert.doesNotMatch(JSON.stringify(config.plugins), /release:npm-publish/);
|
||||
});
|
||||
|
||||
it('configures rc releases from branches with branch-specific prerelease and npm tag', () => {
|
||||
assert.equal(releaseTag('rc', { GITHUB_REF_NAME: 'feature/branch-release' }), 'branch-feature-branch-release');
|
||||
assert.deepEqual(releaseBranches({ KTX_RELEASE_KIND: 'rc', GITHUB_REF_NAME: 'feature/branch-release' }), [
|
||||
{ name: 'main', prerelease: 'rc', channel: 'next' },
|
||||
{ name: 'feature/branch-release', prerelease: 'feature-branch-release', channel: 'branch-feature-branch-release' },
|
||||
]);
|
||||
|
||||
const config = createReleaseConfig({ KTX_RELEASE_KIND: 'rc', GITHUB_REF_NAME: 'feature/branch-release' });
|
||||
assert.match(
|
||||
releaseExecOptions(config).prepareCmd,
|
||||
/update-public-release-version\.mjs "\$\{nextRelease\.version\}" "branch-feature-branch-release"/,
|
||||
);
|
||||
assert.match(
|
||||
releaseExecOptions(config).publishCmd,
|
||||
/^npm publish dist\/artifacts\/npm\/kaelio-ktx-\$\{nextRelease\.version\}\.tgz --tag branch-feature-branch-release --access public --provenance/,
|
||||
);
|
||||
});
|
||||
|
||||
it('configures stable releases only from main with latest tag', () => {
|
||||
assert.equal(releaseKind({ KTX_RELEASE_KIND: 'stable' }), 'stable');
|
||||
assert.equal(releaseTag('stable'), 'latest');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue