feat: use Git notes to store the channels on which a version has been released
BREAKING CHANGE: this feature change the way semantic-release keep track of the channels on which a version has been released. It now use a JSON object stored in a [Git note](https://git-scm.com/docs/git-notes) instead of Git tags formatted as v{version}@{channel}. The tags formatted as v{version}@{channel} will now be ignored. If you have made releases with v16.0.0 on branches other than the default one you will have to update your repository. The changes to make consist in: - Finding all the versions that have been released on a branch other than the default one by searching for all tags formatted v{version}@{channel} - For each of those version: - Create a tag without the {@channel} if none doesn't already exists - Add a Git note to the tag without the {@channel} containing the channels on which the version was released formatted as `{"channels":["channel1","channel2"]}` and using `null` for the default channel (for example.`{"channels":[null,"channel1","channel2"]}`) - Push the tags and notes - Update the GitHub releases that refer to a tag formatted as v{version}@{channel} to use the tag without it - Delete the tags formatted as v{version}@{channel}
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import test from 'ava';
|
||||
import getTags from '../../lib/branches/get-tags';
|
||||
import {gitRepo, gitCommits, gitTagVersion, gitCheckout} from '../helpers/git-utils';
|
||||
import {gitRepo, gitCommits, gitTagVersion, gitCheckout, gitAddNote} from '../helpers/git-utils';
|
||||
|
||||
test('Get the valid tags', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
@@ -20,9 +20,9 @@ test('Get the valid tags', async t => {
|
||||
{
|
||||
name: 'master',
|
||||
tags: [
|
||||
{gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]},
|
||||
{gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]},
|
||||
{gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channels: [undefined]},
|
||||
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null]},
|
||||
{gitTag: 'v2.0.0', version: '2.0.0', channels: [null]},
|
||||
{gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channels: [null]},
|
||||
],
|
||||
},
|
||||
]);
|
||||
@@ -30,20 +30,21 @@ test('Get the valid tags', async t => {
|
||||
|
||||
test('Get the valid tags from multiple branches', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
const commits = await gitCommits(['First'], {cwd});
|
||||
await gitCommits(['First'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
await gitTagVersion('v1.0.0@1.x', undefined, {cwd});
|
||||
commits.push(...(await gitCommits(['Second'], {cwd})));
|
||||
await gitAddNote(JSON.stringify({channels: [null, '1.x']}), 'v1.0.0', {cwd});
|
||||
await gitCommits(['Second'], {cwd});
|
||||
await gitTagVersion('v1.1.0', undefined, {cwd});
|
||||
await gitTagVersion('v1.1.0@1.x', undefined, {cwd});
|
||||
await gitAddNote(JSON.stringify({channels: [null, '1.x']}), 'v1.1.0', {cwd});
|
||||
await gitCheckout('1.x', true, {cwd});
|
||||
await gitCheckout('master', false, {cwd});
|
||||
commits.push(...(await gitCommits(['Third'], {cwd})));
|
||||
await gitCommits(['Third'], {cwd});
|
||||
await gitTagVersion('v2.0.0', undefined, {cwd});
|
||||
await gitTagVersion('v2.0.0@next', undefined, {cwd});
|
||||
await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v2.0.0', {cwd});
|
||||
await gitCheckout('next', true, {cwd});
|
||||
commits.push(...(await gitCommits(['Fourth'], {cwd})));
|
||||
await gitTagVersion('v3.0.0@next', undefined, {cwd});
|
||||
await gitCommits(['Fourth'], {cwd});
|
||||
await gitTagVersion('v3.0.0', undefined, {cwd});
|
||||
await gitAddNote(JSON.stringify({channels: ['next']}), 'v3.0.0', {cwd});
|
||||
|
||||
const result = await getTags({cwd, options: {tagFormat: `v\${version}`}}, [
|
||||
{name: '1.x'},
|
||||
@@ -55,39 +56,17 @@ test('Get the valid tags from multiple branches', async t => {
|
||||
{
|
||||
name: '1.x',
|
||||
tags: [
|
||||
{gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, '1.x']},
|
||||
{gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined, '1.x']},
|
||||
{gitTag: 'v1.0.0', version: '1.0.0', channels: [null, '1.x']},
|
||||
{gitTag: 'v1.1.0', version: '1.1.0', channels: [null, '1.x']},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'master',
|
||||
tags: [...result[0].tags, {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined, 'next']}],
|
||||
tags: [...result[0].tags, {gitTag: 'v2.0.0', version: '2.0.0', channels: [null, 'next']}],
|
||||
},
|
||||
{
|
||||
name: 'next',
|
||||
tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channels: ['next']}],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('Match the tag name from the begining of the string and the channel from the last "@"', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
await gitCommits(['First'], {cwd});
|
||||
await gitTagVersion('prefix@v1.0.0', undefined, {cwd});
|
||||
await gitTagVersion('prefix@v1.0.0@next', undefined, {cwd});
|
||||
await gitTagVersion('prefix@v2.0.0', undefined, {cwd});
|
||||
await gitTagVersion('prefix@v2.0.0@next', undefined, {cwd});
|
||||
await gitTagVersion('other-prefix@v3.0.0', undefined, {cwd});
|
||||
|
||||
const result = await getTags({cwd, options: {tagFormat: `prefix@v\${version}`}}, [{name: 'master'}]);
|
||||
|
||||
t.deepEqual(result, [
|
||||
{
|
||||
name: 'master',
|
||||
tags: [
|
||||
{gitTag: 'prefix@v1.0.0', version: '1.0.0', channels: [undefined, 'next']},
|
||||
{gitTag: 'prefix@v2.0.0', version: '2.0.0', channels: [undefined, 'next']},
|
||||
],
|
||||
tags: [...result[1].tags, {gitTag: 'v3.0.0', version: '3.0.0', channels: ['next']}],
|
||||
},
|
||||
]);
|
||||
});
|
||||
@@ -112,11 +91,13 @@ test('Return branches with and empty tags array if no valid tag is found in hist
|
||||
await gitCheckout('next', true, {cwd});
|
||||
await gitCommits(['Second'], {cwd});
|
||||
await gitTagVersion('v1.0.0', undefined, {cwd});
|
||||
await gitTagVersion('v1.0.0@next', undefined, {cwd});
|
||||
await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v1.0.0', {cwd});
|
||||
await gitCommits(['Third'], {cwd});
|
||||
await gitTagVersion('v2.0.0', undefined, {cwd});
|
||||
await gitTagVersion('v2.0.0@next', undefined, {cwd});
|
||||
await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v2.0.0', {cwd});
|
||||
await gitCommits(['Fourth'], {cwd});
|
||||
await gitTagVersion('v3.0.0', undefined, {cwd});
|
||||
await gitTagVersion('v3.0.0@next', undefined, {cwd});
|
||||
await gitAddNote(JSON.stringify({channels: [null, 'next']}), 'v3.0.0', {cwd});
|
||||
await gitCheckout('master', false, {cwd});
|
||||
|
||||
const result = await getTags({cwd, options: {tagFormat: `prefix@v\${version}`}}, [{name: 'master'}, {name: 'next'}]);
|
||||
@@ -133,19 +114,19 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => {
|
||||
|
||||
await gitTagVersion('1.0.0', undefined, {cwd});
|
||||
t.deepEqual(await getTags({cwd, options: {tagFormat: `\${version}`}}, [{name: 'master'}]), [
|
||||
{name: 'master', tags: [{gitTag: '1.0.0', version: '1.0.0', channels: [undefined]}]},
|
||||
{name: 'master', tags: [{gitTag: '1.0.0', version: '1.0.0', channels: [null]}]},
|
||||
]);
|
||||
|
||||
await gitTagVersion('foo-1.0.0-bar', undefined, {cwd});
|
||||
t.deepEqual(await getTags({cwd, options: {tagFormat: `foo-\${version}-bar`}}, [{name: 'master'}]), [
|
||||
{name: 'master', tags: [{gitTag: 'foo-1.0.0-bar', version: '1.0.0', channels: [undefined]}]},
|
||||
{name: 'master', tags: [{gitTag: 'foo-1.0.0-bar', version: '1.0.0', channels: [null]}]},
|
||||
]);
|
||||
|
||||
await gitTagVersion('foo-v1.0.0-bar', undefined, {cwd});
|
||||
t.deepEqual(await getTags({cwd, options: {tagFormat: `foo-v\${version}-bar`}}, [{name: 'master'}]), [
|
||||
{
|
||||
name: 'master',
|
||||
tags: [{gitTag: 'foo-v1.0.0-bar', version: '1.0.0', channels: [undefined]}],
|
||||
tags: [{gitTag: 'foo-v1.0.0-bar', version: '1.0.0', channels: [null]}],
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -153,7 +134,7 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => {
|
||||
t.deepEqual(await getTags({cwd, options: {tagFormat: `(.+)/\${version}/(a-z)`}}, [{name: 'master'}]), [
|
||||
{
|
||||
name: 'master',
|
||||
tags: [{gitTag: '(.+)/1.0.0/(a-z)', version: '1.0.0', channels: [undefined]}],
|
||||
tags: [{gitTag: '(.+)/1.0.0/(a-z)', version: '1.0.0', channels: [null]}],
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -161,12 +142,12 @@ test('Get the highest valid tag corresponding to the "tagFormat"', async t => {
|
||||
t.deepEqual(await getTags({cwd, options: {tagFormat: `2.0.0-\${version}-bar.1`}}, [{name: 'master'}]), [
|
||||
{
|
||||
name: 'master',
|
||||
tags: [{gitTag: '2.0.0-1.0.0-bar.1', version: '1.0.0', channels: [undefined]}],
|
||||
tags: [{gitTag: '2.0.0-1.0.0-bar.1', version: '1.0.0', channels: [null]}],
|
||||
},
|
||||
]);
|
||||
|
||||
await gitTagVersion('3.0.0-bar.2', undefined, {cwd});
|
||||
t.deepEqual(await getTags({cwd, options: {tagFormat: `\${version}-bar.2`}}, [{name: 'master'}]), [
|
||||
{name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channels: [undefined]}]},
|
||||
{name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channels: [null]}]},
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user