fix: call getTagHead only when necessary

This commit is contained in:
Pierre Vanduynslager
2019-11-07 14:33:53 -05:00
parent 56186419a7
commit de77a799a8
8 changed files with 113 additions and 102 deletions
+6 -1
View File
@@ -18,7 +18,7 @@ const {extractErrors, makeTag} = require('./lib/utils');
const getGitAuthUrl = require('./lib/get-git-auth-url'); const getGitAuthUrl = require('./lib/get-git-auth-url');
const getBranches = require('./lib/branches'); const getBranches = require('./lib/branches');
const getLogger = require('./lib/get-logger'); const getLogger = require('./lib/get-logger');
const {verifyAuth, isBranchUpToDate, getGitHead, tag, push} = require('./lib/git'); const {verifyAuth, isBranchUpToDate, getGitHead, tag, push, getTagHead} = require('./lib/git');
const getError = require('./lib/get-error'); const getError = require('./lib/get-error');
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants'); const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');
@@ -97,6 +97,8 @@ async function run(context, plugins) {
context.releases = []; context.releases = [];
await pEachSeries(releasesToAdd, async ({lastRelease, currentRelease, nextRelease}) => { await pEachSeries(releasesToAdd, async ({lastRelease, currentRelease, nextRelease}) => {
nextRelease.gitHead = await getTagHead(nextRelease.gitHead, {cwd, env});
currentRelease.gitHead = await getTagHead(currentRelease.gitHead, {cwd, env});
if (context.branch.mergeRange && !semver.satisfies(nextRelease.version, context.branch.mergeRange)) { if (context.branch.mergeRange && !semver.satisfies(nextRelease.version, context.branch.mergeRange)) {
errors.push(getError('EINVALIDMAINTENANCEMERGE', {...context, nextRelease})); errors.push(getError('EINVALIDMAINTENANCEMERGE', {...context, nextRelease}));
return; return;
@@ -125,6 +127,9 @@ async function run(context, plugins) {
} }
context.lastRelease = await getLastRelease(context); context.lastRelease = await getLastRelease(context);
if (context.lastRelease.gitHead) {
context.lastRelease.gitHead = await getTagHead(context.lastRelease.gitHead, {cwd, env});
}
if (context.lastRelease.gitTag) { if (context.lastRelease.gitTag) {
logger.log( logger.log(
+2 -2
View File
@@ -2,7 +2,7 @@ const {template, escapeRegExp} = require('lodash');
const semver = require('semver'); const semver = require('semver');
const pReduce = require('p-reduce'); const pReduce = require('p-reduce');
const debug = require('debug')('semantic-release:get-tags'); const debug = require('debug')('semantic-release:get-tags');
const {getTags, getTagHead} = require('../../lib/git'); const {getTags} = require('../../lib/git');
module.exports = async ({cwd, env, options: {tagFormat}}, branches) => { module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
// Generate a regex to parse tags formatted with `tagFormat` // Generate a regex to parse tags formatted with `tagFormat`
@@ -21,7 +21,7 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
return {gitTag: tag, version, channel}; return {gitTag: tag, version, channel};
}) })
.filter(({version}) => version && semver.valid(semver.clean(version))) .filter(({version}) => version && semver.valid(semver.clean(version)))
.map(async ({gitTag, ...rest}) => ({gitTag, gitHead: await getTagHead(gitTag, {cwd, env}), ...rest})) .map(async ({gitTag, ...rest}) => ({gitTag, ...rest}))
); );
debug('found tags for branch %s: %o', branch.name, branchTags); debug('found tags for branch %s: %o', branch.name, branchTags);
+6 -3
View File
@@ -7,7 +7,10 @@ const {makeTag} = require('./utils');
* *
* @typedef {Object} LastRelease * @typedef {Object} LastRelease
* @property {string} version The version number of the last release. * @property {string} version The version number of the last release.
* @property {string} [gitHead] The Git reference used to make the last release. * @property {string} gitHead The Git reference used to make the last release.
* @property {string} gitTag The git tag associated with the last release.
* @property {string} channel The channel on which of the last release was published.
* @property {string} name The name of the last release.
*/ */
/** /**
@@ -24,13 +27,13 @@ const {makeTag} = require('./utils');
* @return {LastRelease} The last tagged release or empty object if none is found. * @return {LastRelease} The last tagged release or empty object if none is found.
*/ */
module.exports = ({branch, options: {tagFormat}}, {before} = {}) => { module.exports = ({branch, options: {tagFormat}}, {before} = {}) => {
const [{version, gitTag, gitHead, channel} = {}] = branch.tags const [{version, gitTag, channel} = {}] = branch.tags
.filter(tag => (branch.type === 'prerelease' && branch.channel === tag.channel) || !semver.prerelease(tag.version)) .filter(tag => (branch.type === 'prerelease' && branch.channel === tag.channel) || !semver.prerelease(tag.version))
.filter(tag => isUndefined(before) || semver.lt(tag.version, before)) .filter(tag => isUndefined(before) || semver.lt(tag.version, before))
.sort((a, b) => semver.rcompare(a.version, b.version)); .sort((a, b) => semver.rcompare(a.version, b.version));
if (gitTag) { if (gitTag) {
return {version, gitTag, gitHead, channel, name: makeTag(tagFormat, version)}; return {version, gitTag, channel, gitHead: gitTag, name: makeTag(tagFormat, version)};
} }
return {}; return {};
+3 -3
View File
@@ -47,20 +47,20 @@ module.exports = context => {
// Sort in ascending order to add the most recent release last // Sort in ascending order to add the most recent release last
.sort((a, b) => semver.compare(a.version, b.version)) .sort((a, b) => semver.compare(a.version, b.version))
// Construct the last and next release to add to the building branch channel // Construct the last and next release to add to the building branch channel
.map(({version, gitHead, gitTag}) => { .map(({version, gitTag}) => {
const lastRelease = getLastRelease(context, {before: version}); const lastRelease = getLastRelease(context, {before: version});
const type = lastRelease.version ? semverDiff(lastRelease.version, version) : 'major'; const type = lastRelease.version ? semverDiff(lastRelease.version, version) : 'major';
const name = makeTag(tagFormat, version); const name = makeTag(tagFormat, version);
return { return {
lastRelease, lastRelease,
currentRelease: {type, version, channel: higherBranch.channel, gitTag, name, gitHead}, currentRelease: {type, version, channel: higherBranch.channel, gitTag, name, gitHead: gitTag},
nextRelease: { nextRelease: {
type, type,
version, version,
channel: branch.channel, channel: branch.channel,
gitTag: makeTag(tagFormat, version, branch.channel), gitTag: makeTag(tagFormat, version, branch.channel),
name, name,
gitHead, gitHead: gitTag,
}, },
}; };
}), }),
+22 -22
View File
@@ -20,9 +20,9 @@ test('Get the valid tags', async t => {
{ {
name: 'master', name: 'master',
tags: [ tags: [
{gitTag: 'v1.0.0', version: '1.0.0', channel: undefined, gitHead: commits[1].hash}, {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined},
{gitTag: 'v2.0.0', version: '2.0.0', channel: undefined, gitHead: commits[0].hash}, {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined},
{gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channel: undefined, gitHead: commits[3].hash}, {gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channel: undefined},
], ],
}, },
]); ]);
@@ -55,30 +55,30 @@ test('Get the valid tags from multiple branches', async t => {
{ {
name: '1.x', name: '1.x',
tags: [ tags: [
{gitTag: 'v1.0.0', version: '1.0.0', channel: undefined, gitHead: commits[0].hash}, {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined},
{gitTag: 'v1.0.0@1.x', version: '1.0.0', channel: '1.x', gitHead: commits[0].hash}, {gitTag: 'v1.0.0@1.x', version: '1.0.0', channel: '1.x'},
{gitTag: 'v1.1.0', version: '1.1.0', channel: undefined, gitHead: commits[1].hash}, {gitTag: 'v1.1.0', version: '1.1.0', channel: undefined},
{gitTag: 'v1.1.0@1.x', version: '1.1.0', channel: '1.x', gitHead: commits[1].hash}, {gitTag: 'v1.1.0@1.x', version: '1.1.0', channel: '1.x'},
], ],
}, },
{ {
name: 'master', name: 'master',
tags: [ tags: [
...result[0].tags, ...result[0].tags,
{gitTag: 'v2.0.0', version: '2.0.0', channel: undefined, gitHead: commits[2].hash}, {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined},
{gitTag: 'v2.0.0@next', version: '2.0.0', channel: 'next', gitHead: commits[2].hash}, {gitTag: 'v2.0.0@next', version: '2.0.0', channel: 'next'},
], ],
}, },
{ {
name: 'next', name: 'next',
tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channel: 'next', gitHead: commits[3].hash}], tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channel: 'next'}],
}, },
]); ]);
}); });
test('Match the tag name from the begining of the string and the channel from the last "@"', async t => { test('Match the tag name from the begining of the string and the channel from the last "@"', async t => {
const {cwd} = await gitRepo(); const {cwd} = await gitRepo();
const commits = await gitCommits(['First'], {cwd}); await gitCommits(['First'], {cwd});
await gitTagVersion('prefix@v1.0.0', undefined, {cwd}); await gitTagVersion('prefix@v1.0.0', undefined, {cwd});
await gitTagVersion('prefix@v1.0.0@next', 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', undefined, {cwd});
@@ -91,10 +91,10 @@ test('Match the tag name from the begining of the string and the channel from th
{ {
name: 'master', name: 'master',
tags: [ tags: [
{gitTag: 'prefix@v1.0.0', version: '1.0.0', channel: undefined, gitHead: commits[0].hash}, {gitTag: 'prefix@v1.0.0', version: '1.0.0', channel: undefined},
{gitTag: 'prefix@v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: commits[0].hash}, {gitTag: 'prefix@v1.0.0@next', version: '1.0.0', channel: 'next'},
{gitTag: 'prefix@v2.0.0', version: '2.0.0', channel: undefined, gitHead: commits[0].hash}, {gitTag: 'prefix@v2.0.0', version: '2.0.0', channel: undefined},
{gitTag: 'prefix@v2.0.0@next', version: '2.0.0', channel: 'next', gitHead: commits[0].hash}, {gitTag: 'prefix@v2.0.0@next', version: '2.0.0', channel: 'next'},
], ],
}, },
]); ]);
@@ -134,23 +134,23 @@ test('Return branches with and empty tags array if no valid tag is found in hist
test('Get the highest valid tag corresponding to the "tagFormat"', async t => { test('Get the highest valid tag corresponding to the "tagFormat"', async t => {
const {cwd} = await gitRepo(); const {cwd} = await gitRepo();
const commits = await gitCommits(['First'], {cwd}); await gitCommits(['First'], {cwd});
await gitTagVersion('1.0.0', undefined, {cwd}); await gitTagVersion('1.0.0', undefined, {cwd});
t.deepEqual(await getTags({cwd, options: {tagFormat: `\${version}`}}, [{name: 'master'}]), [ t.deepEqual(await getTags({cwd, options: {tagFormat: `\${version}`}}, [{name: 'master'}]), [
{name: 'master', tags: [{gitTag: '1.0.0', version: '1.0.0', channel: undefined, gitHead: commits[0].hash}]}, {name: 'master', tags: [{gitTag: '1.0.0', version: '1.0.0', channel: undefined}]},
]); ]);
await gitTagVersion('foo-1.0.0-bar', undefined, {cwd}); await gitTagVersion('foo-1.0.0-bar', undefined, {cwd});
t.deepEqual(await getTags({cwd, options: {tagFormat: `foo-\${version}-bar`}}, [{name: 'master'}]), [ 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', channel: undefined, gitHead: commits[0].hash}]}, {name: 'master', tags: [{gitTag: 'foo-1.0.0-bar', version: '1.0.0', channel: undefined}]},
]); ]);
await gitTagVersion('foo-v1.0.0-bar', undefined, {cwd}); await gitTagVersion('foo-v1.0.0-bar', undefined, {cwd});
t.deepEqual(await getTags({cwd, options: {tagFormat: `foo-v\${version}-bar`}}, [{name: 'master'}]), [ t.deepEqual(await getTags({cwd, options: {tagFormat: `foo-v\${version}-bar`}}, [{name: 'master'}]), [
{ {
name: 'master', name: 'master',
tags: [{gitTag: 'foo-v1.0.0-bar', version: '1.0.0', channel: undefined, gitHead: commits[0].hash}], tags: [{gitTag: 'foo-v1.0.0-bar', version: '1.0.0', channel: undefined}],
}, },
]); ]);
@@ -158,7 +158,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'}]), [ t.deepEqual(await getTags({cwd, options: {tagFormat: `(.+)/\${version}/(a-z)`}}, [{name: 'master'}]), [
{ {
name: 'master', name: 'master',
tags: [{gitTag: '(.+)/1.0.0/(a-z)', version: '1.0.0', channel: undefined, gitHead: commits[0].hash}], tags: [{gitTag: '(.+)/1.0.0/(a-z)', version: '1.0.0', channel: undefined}],
}, },
]); ]);
@@ -166,12 +166,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'}]), [ t.deepEqual(await getTags({cwd, options: {tagFormat: `2.0.0-\${version}-bar.1`}}, [{name: 'master'}]), [
{ {
name: 'master', name: 'master',
tags: [{gitTag: '2.0.0-1.0.0-bar.1', version: '1.0.0', channel: undefined, gitHead: commits[0].hash}], tags: [{gitTag: '2.0.0-1.0.0-bar.1', version: '1.0.0', channel: undefined}],
}, },
]); ]);
await gitTagVersion('3.0.0-bar.2', undefined, {cwd}); await gitTagVersion('3.0.0-bar.2', undefined, {cwd});
t.deepEqual(await getTags({cwd, options: {tagFormat: `\${version}-bar.2`}}, [{name: 'master'}]), [ 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', channel: undefined, gitHead: commits[0].hash}]}, {name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channel: undefined}]},
]); ]);
}); });
+15 -15
View File
@@ -6,16 +6,16 @@ test('Get the highest non-prerelease valid tag', t => {
branch: { branch: {
name: 'master', name: 'master',
tags: [ tags: [
{version: '2.0.0', gitTag: 'v2.0.0', gitHead: '222'}, {version: '2.0.0', gitTag: 'v2.0.0', gitHead: 'v2.0.0'},
{version: '1.0.0', gitTag: 'v1.0.0', gitHead: '111'}, {version: '1.0.0', gitTag: 'v1.0.0', gitHead: 'v1.0.0'},
{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: '333'}, {version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: 'v3.0.0-beta.1@beta'},
], ],
type: 'release', type: 'release',
}, },
options: {tagFormat: `v\${version}`}, options: {tagFormat: `v\${version}`},
}); });
t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: '222', channel: undefined}); t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channel: undefined});
}); });
test('Get the highest prerelease valid tag, ignoring other tags from other prerelease channels', t => { test('Get the highest prerelease valid tag, ignoring other tags from other prerelease channels', t => {
@@ -25,9 +25,9 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere
prerelease: 'beta', prerelease: 'beta',
channel: 'beta', channel: 'beta',
tags: [ tags: [
{version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1@beta', gitHead: '111', channel: 'beta'}, {version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1@beta', gitHead: 'v1.0.0-beta.1@beta', channel: 'beta'},
{version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', gitHead: '222', channel: 'beta'}, {version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', gitHead: 'v1.0.0-beta.2@beta', channel: 'beta'},
{version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1@alpha', gitHead: '333', channel: 'alpha'}, {version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1@alpha', gitHead: 'v1.0.0-alpha.1@alpha', channel: 'alpha'},
], ],
type: 'prerelease', type: 'prerelease',
}, },
@@ -38,7 +38,7 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere
version: '1.0.0-beta.2', version: '1.0.0-beta.2',
gitTag: 'v1.0.0-beta.2@beta', gitTag: 'v1.0.0-beta.2@beta',
name: 'v1.0.0-beta.2', name: 'v1.0.0-beta.2',
gitHead: '222', gitHead: 'v1.0.0-beta.2@beta',
channel: 'beta', channel: 'beta',
}); });
}); });
@@ -47,7 +47,7 @@ test('Return empty object if no valid tag is found', t => {
const result = getLastRelease({ const result = getLastRelease({
branch: { branch: {
name: 'master', name: 'master',
tags: [{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: '111'}], tags: [{version: '3.0.0-beta.1', gitTag: 'v3.0.0-beta.1@beta', gitHead: 'v3.0.0-beta.1@beta'}],
type: 'release', type: 'release',
}, },
options: {tagFormat: `v\${version}`}, options: {tagFormat: `v\${version}`},
@@ -63,11 +63,11 @@ test('Get the highest non-prerelease valid tag before a certain version', t => {
name: 'master', name: 'master',
channel: undefined, channel: undefined,
tags: [ tags: [
{version: '2.0.0', gitTag: 'v2.0.0', gitHead: '333'}, {version: '2.0.0', gitTag: 'v2.0.0', gitHead: 'v2.0.0'},
{version: '1.0.0', gitTag: 'v1.0.0', gitHead: '111'}, {version: '1.0.0', gitTag: 'v1.0.0', gitHead: 'v1.0.0'},
{version: '2.0.0-beta.1', gitTag: 'v2.0.0-beta.1@beta', gitHead: '222'}, {version: '2.0.0-beta.1', gitTag: 'v2.0.0-beta.1@beta', gitHead: 'v2.0.0-beta.1@beta'},
{version: '2.1.0', gitTag: 'v2.1.0', gitHead: '444'}, {version: '2.1.0', gitTag: 'v2.1.0', gitHead: 'v2.1.0'},
{version: '2.1.1', gitTag: 'v2.1.1', gitHead: '555'}, {version: '2.1.1', gitTag: 'v2.1.1', gitHead: 'v2.1.1'},
], ],
type: 'release', type: 'release',
}, },
@@ -76,5 +76,5 @@ test('Get the highest non-prerelease valid tag before a certain version', t => {
{before: '2.1.0'} {before: '2.1.0'}
); );
t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: '333', channel: undefined}); t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channel: undefined});
}); });
+57 -54
View File
@@ -9,12 +9,12 @@ test('Return versions merged from release to maintenance branch, excluding lower
type: 'maintenance', type: 'maintenance',
mergeRange: '>=2.0.0 <3.0.0', mergeRange: '>=2.0.0 <3.0.0',
tags: [ tags: [
{gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x', gitHead: '111'}, {gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x'},
{gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, {gitTag: 'v2.0.0', version: '2.0.0'},
{gitTag: 'v2.1.0', version: '2.1.0', gitHead: '222'}, {gitTag: 'v2.1.0', version: '2.1.0'},
{gitTag: 'v2.1.1', version: '2.1.1', gitHead: '333'}, {gitTag: 'v2.1.1', version: '2.1.1'},
{gitTag: 'v1.0.0', version: '1.0.0', gitHead: '444'}, {gitTag: 'v1.0.0', version: '1.0.0'},
{gitTag: 'v1.1.0', version: '1.1.0', gitHead: '555'}, {gitTag: 'v1.1.0', version: '1.1.0'},
], ],
}, },
branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}], branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}],
@@ -23,14 +23,14 @@ test('Return versions merged from release to maintenance branch, excluding lower
t.deepEqual(result, [ t.deepEqual(result, [
{ {
lastRelease: {version: '2.0.0', channel: '2.x', gitTag: 'v2.0.0@2.x', name: 'v2.0.0', gitHead: '111'}, lastRelease: {version: '2.0.0', channel: '2.x', gitTag: 'v2.0.0@2.x', name: 'v2.0.0', gitHead: 'v2.0.0@2.x'},
currentRelease: { currentRelease: {
type: 'minor', type: 'minor',
version: '2.1.0', version: '2.1.0',
channel: undefined, channel: undefined,
gitTag: 'v2.1.0', gitTag: 'v2.1.0',
name: 'v2.1.0', name: 'v2.1.0',
gitHead: '222', gitHead: 'v2.1.0',
}, },
nextRelease: { nextRelease: {
type: 'minor', type: 'minor',
@@ -38,18 +38,18 @@ test('Return versions merged from release to maintenance branch, excluding lower
channel: '2.x', channel: '2.x',
gitTag: 'v2.1.0@2.x', gitTag: 'v2.1.0@2.x',
name: 'v2.1.0', name: 'v2.1.0',
gitHead: '222', gitHead: 'v2.1.0',
}, },
}, },
{ {
lastRelease: {version: '2.1.0', channel: undefined, gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: '222'}, lastRelease: {version: '2.1.0', channel: undefined, gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: 'v2.1.0'},
currentRelease: { currentRelease: {
type: 'patch', type: 'patch',
version: '2.1.1', version: '2.1.1',
channel: undefined, channel: undefined,
gitTag: 'v2.1.1', gitTag: 'v2.1.1',
name: 'v2.1.1', name: 'v2.1.1',
gitHead: '333', gitHead: 'v2.1.1',
}, },
nextRelease: { nextRelease: {
type: 'patch', type: 'patch',
@@ -57,7 +57,7 @@ test('Return versions merged from release to maintenance branch, excluding lower
channel: '2.x', channel: '2.x',
gitTag: 'v2.1.1@2.x', gitTag: 'v2.1.1@2.x',
name: 'v2.1.1', name: 'v2.1.1',
gitHead: '333', gitHead: 'v2.1.1',
}, },
}, },
]); ]);
@@ -68,10 +68,10 @@ test('Return versions merged between release branches', t => {
branch: { branch: {
name: 'master', name: 'master',
tags: [ tags: [
{gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, {gitTag: 'v1.0.0', version: '1.0.0'},
{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}, {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'},
{gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next', gitHead: '222'}, {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'},
{gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major', gitHead: '333'}, {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major'},
], ],
}, },
branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}],
@@ -80,14 +80,14 @@ test('Return versions merged between release branches', t => {
t.deepEqual(result, [ t.deepEqual(result, [
{ {
lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: '111'}, lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'},
currentRelease: { currentRelease: {
type: 'minor', type: 'minor',
version: '1.1.0', version: '1.1.0',
channel: 'next', channel: 'next',
gitTag: 'v1.1.0@next', gitTag: 'v1.1.0@next',
name: 'v1.1.0', name: 'v1.1.0',
gitHead: '222', gitHead: 'v1.1.0@next',
}, },
nextRelease: { nextRelease: {
type: 'minor', type: 'minor',
@@ -95,18 +95,18 @@ test('Return versions merged between release branches', t => {
channel: undefined, channel: undefined,
gitTag: 'v1.1.0', gitTag: 'v1.1.0',
name: 'v1.1.0', name: 'v1.1.0',
gitHead: '222', gitHead: 'v1.1.0@next',
}, },
}, },
{ {
lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: '222', channel: 'next'}, lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channel: 'next'},
currentRelease: { currentRelease: {
type: 'major', type: 'major',
version: '2.0.0', version: '2.0.0',
channel: 'next-major', channel: 'next-major',
gitTag: 'v2.0.0@next-major', gitTag: 'v2.0.0@next-major',
name: 'v2.0.0', name: 'v2.0.0',
gitHead: '333', gitHead: 'v2.0.0@next-major',
}, },
nextRelease: { nextRelease: {
type: 'major', type: 'major',
@@ -114,7 +114,7 @@ test('Return versions merged between release branches', t => {
channel: undefined, channel: undefined,
gitTag: 'v2.0.0', gitTag: 'v2.0.0',
name: 'v2.0.0', name: 'v2.0.0',
gitHead: '333', gitHead: 'v2.0.0@next-major',
}, },
}, },
]); ]);
@@ -125,10 +125,10 @@ test('Return releases sorted by ascending order', t => {
branch: { branch: {
name: 'master', name: 'master',
tags: [ tags: [
{gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major', gitHead: '333'}, {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major'},
{gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next', gitHead: '222'}, {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'},
{gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, {gitTag: 'v1.0.0', version: '1.0.0'},
{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}, {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'},
], ],
}, },
branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}],
@@ -137,14 +137,14 @@ test('Return releases sorted by ascending order', t => {
t.deepEqual(result, [ t.deepEqual(result, [
{ {
lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: '111'}, lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'},
currentRelease: { currentRelease: {
type: 'minor', type: 'minor',
version: '1.1.0', version: '1.1.0',
channel: 'next', channel: 'next',
gitTag: 'v1.1.0@next', gitTag: 'v1.1.0@next',
name: 'v1.1.0', name: 'v1.1.0',
gitHead: '222', gitHead: 'v1.1.0@next',
}, },
nextRelease: { nextRelease: {
type: 'minor', type: 'minor',
@@ -152,18 +152,18 @@ test('Return releases sorted by ascending order', t => {
channel: undefined, channel: undefined,
gitTag: 'v1.1.0', gitTag: 'v1.1.0',
name: 'v1.1.0', name: 'v1.1.0',
gitHead: '222', gitHead: 'v1.1.0@next',
}, },
}, },
{ {
lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: '222', channel: 'next'}, lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channel: 'next'},
currentRelease: { currentRelease: {
type: 'major', type: 'major',
version: '2.0.0', version: '2.0.0',
channel: 'next-major', channel: 'next-major',
gitTag: 'v2.0.0@next-major', gitTag: 'v2.0.0@next-major',
name: 'v2.0.0', name: 'v2.0.0',
gitHead: '333', gitHead: 'v2.0.0@next-major',
}, },
nextRelease: { nextRelease: {
type: 'major', type: 'major',
@@ -171,7 +171,7 @@ test('Return releases sorted by ascending order', t => {
channel: undefined, channel: undefined,
gitTag: 'v2.0.0', gitTag: 'v2.0.0',
name: 'v2.0.0', name: 'v2.0.0',
gitHead: '333', gitHead: 'v2.0.0@next-major',
}, },
}, },
]); ]);
@@ -179,7 +179,10 @@ test('Return releases sorted by ascending order', t => {
test('No lastRelease', t => { test('No lastRelease', t => {
const result = getReleasesToAdd({ const result = getReleasesToAdd({
branch: {name: 'master', tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}]}, branch: {
name: 'master',
tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}],
},
branches: [{name: 'master'}, {name: 'next', channel: 'next'}], branches: [{name: 'master'}, {name: 'next', channel: 'next'}],
options: {tagFormat: `v\${version}`}, options: {tagFormat: `v\${version}`},
}); });
@@ -193,7 +196,7 @@ test('No lastRelease', t => {
channel: 'next', channel: 'next',
gitTag: 'v1.0.0@next', gitTag: 'v1.0.0@next',
name: 'v1.0.0', name: 'v1.0.0',
gitHead: '111', gitHead: 'v1.0.0@next',
}, },
nextRelease: { nextRelease: {
type: 'major', type: 'major',
@@ -201,7 +204,7 @@ test('No lastRelease', t => {
channel: undefined, channel: undefined,
gitTag: 'v1.0.0', gitTag: 'v1.0.0',
name: 'v1.0.0', name: 'v1.0.0',
gitHead: '111', gitHead: 'v1.0.0@next',
}, },
}, },
]); ]);
@@ -212,10 +215,10 @@ test('Ignore pre-release versions', t => {
branch: { branch: {
name: 'master', name: 'master',
tags: [ tags: [
{gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, {gitTag: 'v1.0.0', version: '1.0.0'},
{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}, {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'},
{gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next', gitHead: '222'}, {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'},
{gitTag: 'v2.0.0-alpha.1@alpha', version: '2.0.0', channel: 'alpha', gitHead: '333'}, {gitTag: 'v2.0.0-alpha.1@alpha', version: '2.0.0', channel: 'alpha'},
], ],
}, },
branches: [ branches: [
@@ -228,14 +231,14 @@ test('Ignore pre-release versions', t => {
t.deepEqual(result, [ t.deepEqual(result, [
{ {
lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: '111'}, lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'},
currentRelease: { currentRelease: {
type: 'minor', type: 'minor',
version: '1.1.0', version: '1.1.0',
channel: 'next', channel: 'next',
gitTag: 'v1.1.0@next', gitTag: 'v1.1.0@next',
name: 'v1.1.0', name: 'v1.1.0',
gitHead: '222', gitHead: 'v1.1.0@next',
}, },
nextRelease: { nextRelease: {
type: 'minor', type: 'minor',
@@ -243,7 +246,7 @@ test('Ignore pre-release versions', t => {
channel: undefined, channel: undefined,
gitTag: 'v1.1.0', gitTag: 'v1.1.0',
name: 'v1.1.0', name: 'v1.1.0',
gitHead: '222', gitHead: 'v1.1.0@next',
}, },
}, },
]); ]);
@@ -257,12 +260,12 @@ test('Exclude versions merged from release to maintenance branch if they have th
type: 'maintenance', type: 'maintenance',
mergeRange: '>=2.0.0 <3.0.0', mergeRange: '>=2.0.0 <3.0.0',
tags: [ tags: [
{gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, {gitTag: 'v2.0.0', version: '2.0.0'},
{gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, {gitTag: 'v2.0.0', version: '2.0.0'},
{gitTag: 'v2.1.0', version: '2.1.0', gitHead: '222'}, {gitTag: 'v2.1.0', version: '2.1.0'},
{gitTag: 'v2.1.1', version: '2.1.1', gitHead: '333'}, {gitTag: 'v2.1.1', version: '2.1.1'},
{gitTag: 'v1.0.0', version: '1.0.0', gitHead: '444'}, {gitTag: 'v1.0.0', version: '1.0.0'},
{gitTag: 'v1.1.0', version: '1.1.0', gitHead: '555'}, {gitTag: 'v1.1.0', version: '1.1.0'},
], ],
}, },
branches: [{name: '2.x', channel: 'latest'}, {name: 'master', channel: 'latest'}], branches: [{name: '2.x', channel: 'latest'}, {name: 'master', channel: 'latest'}],
@@ -278,9 +281,9 @@ test('Exclude versions merged between release branches if they have the same "ch
name: 'master', name: 'master',
channel: 'latest', channel: 'latest',
tags: [ tags: [
{gitTag: 'v1.0.0', channel: 'latest', version: '1.0.0', gitHead: '111'}, {gitTag: 'v1.0.0', channel: 'latest', version: '1.0.0'},
{gitTag: 'v1.1.0', channel: 'latest', version: '1.1.0', gitHead: '222'}, {gitTag: 'v1.1.0', channel: 'latest', version: '1.1.0'},
{gitTag: 'v2.0.0', channel: 'latest', version: '2.0.0', gitHead: '333'}, {gitTag: 'v2.0.0', channel: 'latest', version: '2.0.0'},
], ],
}, },
branches: [ branches: [
@@ -300,9 +303,9 @@ test('Exclude versions merged between release branches if they all have "channel
name: 'master', name: 'master',
channel: false, channel: false,
tags: [ tags: [
{gitTag: 'v1.0.0', version: '1.0.0', gitHead: '111'}, {gitTag: 'v1.0.0', version: '1.0.0'},
{gitTag: 'v1.1.0', version: '1.1.0', gitHead: '222'}, {gitTag: 'v1.1.0', version: '1.1.0'},
{gitTag: 'v2.0.0', version: '2.0.0', gitHead: '333'}, {gitTag: 'v2.0.0', version: '2.0.0'},
], ],
}, },
branches: [{name: 'master', channel: false}, {name: 'next', channel: false}, {name: 'next-major', channel: false}], branches: [{name: 'master', channel: false}, {name: 'next', channel: false}, {name: 'next-major', channel: false}],
+2 -2
View File
@@ -96,7 +96,7 @@ test('Plugins are called with expected values', async t => {
name: 'master', name: 'master',
range: '>=1.0.0 <2.0.0', range: '>=1.0.0 <2.0.0',
accept: ['patch', 'minor'], accept: ['patch', 'minor'],
tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0', gitHead: commits[commits.length - 1].hash}], tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0'}],
type: 'release', type: 'release',
}, },
{ {
@@ -104,7 +104,7 @@ test('Plugins are called with expected values', async t => {
name: 'next', name: 'next',
range: '>=2.0.0', range: '>=2.0.0',
accept: ['patch', 'minor', 'major'], accept: ['patch', 'minor', 'major'],
tags: [{channel: 'next', gitHead: commits[commits.length - 1].hash, gitTag: 'v1.0.0@next', version: '1.0.0'}], tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0'}],
type: 'release', type: 'release',
}, },
]; ];