fix: correctly determine release to add to a channel
- Add only the most recent release to a channel (rather than adding all the one not added yet) - Avoid attempting to ad the version twice in case that version is already present in multiple upper branches
This commit is contained in:
		
							parent
							
								
									5744c5ecd2
								
							
						
					
					
						commit
						aec96c791f
					
				
							
								
								
									
										21
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								index.js
									
									
									
									
									
								
							| @ -3,7 +3,6 @@ const marked = require('marked'); | ||||
| const TerminalRenderer = require('marked-terminal'); | ||||
| const envCi = require('env-ci'); | ||||
| const hookStd = require('hook-std'); | ||||
| const pEachSeries = require('p-each-series'); | ||||
| const semver = require('semver'); | ||||
| const AggregateError = require('aggregate-error'); | ||||
| const pkg = require('./package.json'); | ||||
| @ -13,7 +12,7 @@ const verify = require('./lib/verify'); | ||||
| const getNextVersion = require('./lib/get-next-version'); | ||||
| const getCommits = require('./lib/get-commits'); | ||||
| const getLastRelease = require('./lib/get-last-release'); | ||||
| const getReleasesToAdd = require('./lib/get-releases-to-add'); | ||||
| const getReleaseToAdd = require('./lib/get-release-to-add'); | ||||
| const {extractErrors, makeTag} = require('./lib/utils'); | ||||
| const getGitAuthUrl = require('./lib/get-git-auth-url'); | ||||
| const getBranches = require('./lib/branches'); | ||||
| @ -24,7 +23,7 @@ const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants'); | ||||
| 
 | ||||
| marked.setOptions({renderer: new TerminalRenderer()}); | ||||
| 
 | ||||
| /* eslint complexity: ["warn", 25] */ | ||||
| /* eslint complexity: off */ | ||||
| async function run(context, plugins) { | ||||
|   const {cwd, env, options, logger} = context; | ||||
|   const {isCi, branch: ciBranch, isPr} = envCi({env, cwd}); | ||||
| @ -92,24 +91,25 @@ async function run(context, plugins) { | ||||
| 
 | ||||
|   await plugins.verifyConditions(context); | ||||
| 
 | ||||
|   const releasesToAdd = getReleasesToAdd(context); | ||||
|   const errors = []; | ||||
|   context.releases = []; | ||||
|   const releaseToAdd = getReleaseToAdd(context); | ||||
| 
 | ||||
|   if (releaseToAdd) { | ||||
|     const {lastRelease, currentRelease, nextRelease} = releaseToAdd; | ||||
| 
 | ||||
|   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)) { | ||||
|       errors.push(getError('EINVALIDMAINTENANCEMERGE', {...context, nextRelease})); | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|     } else { | ||||
|       const commits = await getCommits({...context, lastRelease, nextRelease}); | ||||
|       nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease}); | ||||
| 
 | ||||
|     logger.log('Create tag %s', nextRelease.gitTag); | ||||
|       await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env}); | ||||
|       await push(options.repositoryUrl, {cwd, env}); | ||||
|       logger.success(`Created tag ${nextRelease.gitTag}`); | ||||
| 
 | ||||
|       context.branch.tags.push({ | ||||
|         version: nextRelease.version, | ||||
|         channel: nextRelease.channel, | ||||
| @ -120,7 +120,8 @@ async function run(context, plugins) { | ||||
|       const releases = await plugins.addChannel({...context, commits, lastRelease, currentRelease, nextRelease}); | ||||
|       context.releases.push(...releases); | ||||
|       await plugins.success({...context, lastRelease, commits, nextRelease, releases}); | ||||
|   }); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   if (errors.length > 0) { | ||||
|     throw new AggregateError(errors); | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| const {template, escapeRegExp} = require('lodash'); | ||||
| const {template, escapeRegExp, flatMap} = require('lodash'); | ||||
| const semver = require('semver'); | ||||
| const pReduce = require('p-reduce'); | ||||
| const debug = require('debug')('semantic-release:get-tags'); | ||||
| @ -14,10 +14,21 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => { | ||||
|   return pReduce( | ||||
|     branches, | ||||
|     async (branches, branch) => { | ||||
|       const branchTags = (await getTags(branch.name, {cwd, env})).reduce((tags, tag) => { | ||||
|       const versions = (await getTags(branch.name, {cwd, env})).reduce((versions, tag) => { | ||||
|         const [, version, channel] = tag.match(tagRegexp) || []; | ||||
|         return version && semver.valid(semver.clean(version)) ? [...tags, {gitTag: tag, version, channel}] : tags; | ||||
|       }, []); | ||||
|         if (version && semver.valid(semver.clean(version))) { | ||||
|           return { | ||||
|             ...versions, | ||||
|             [version]: versions[version] | ||||
|               ? {...versions[version], channels: [...versions[version].channels, channel]} | ||||
|               : {gitTag: tag, version, channels: [channel]}, | ||||
|           }; | ||||
|         } | ||||
| 
 | ||||
|         return versions; | ||||
|       }, {}); | ||||
| 
 | ||||
|       const branchTags = flatMap(versions); | ||||
| 
 | ||||
|       debug('found tags for branch %s: %o', branch.name, branchTags); | ||||
|       return [...branches, {...branch, tags: branchTags}]; | ||||
|  | ||||
| @ -27,16 +27,17 @@ const {makeTag, isSameChannel} = require('./utils'); | ||||
|  * @return {LastRelease} The last tagged release or empty object if none is found. | ||||
|  */ | ||||
| module.exports = ({branch, options: {tagFormat}}, {before} = {}) => { | ||||
|   const [{version, gitTag, channel} = {}] = branch.tags | ||||
|   const [{version, gitTag, channels} = {}] = branch.tags | ||||
|     .filter( | ||||
|       tag => | ||||
|         (branch.type === 'prerelease' && isSameChannel(branch.channel, tag.channel)) || !semver.prerelease(tag.version) | ||||
|         (branch.type === 'prerelease' && tag.channels.some(channel => isSameChannel(branch.channel, channel))) || | ||||
|         !semver.prerelease(tag.version) | ||||
|     ) | ||||
|     .filter(tag => isUndefined(before) || semver.lt(tag.version, before)) | ||||
|     .sort((a, b) => semver.rcompare(a.version, b.version)); | ||||
| 
 | ||||
|   if (gitTag) { | ||||
|     return {version, gitTag, channel, gitHead: gitTag, name: makeTag(tagFormat, version)}; | ||||
|     return {version, gitTag, channels, gitHead: gitTag, name: makeTag(tagFormat, version)}; | ||||
|   } | ||||
| 
 | ||||
|   return {}; | ||||
|  | ||||
| @ -8,7 +8,8 @@ module.exports = ({branch, nextRelease: {type, channel}, lastRelease, logger}) = | ||||
|     const {major, minor, patch} = semver.parse(lastRelease.version); | ||||
|     version = | ||||
|       branch.type === 'prerelease' | ||||
|         ? semver.prerelease(lastRelease.version) && isSameChannel(lastRelease.channel, channel) | ||||
|         ? semver.prerelease(lastRelease.version) && | ||||
|           lastRelease.channels.some(lastReleaseChannel => isSameChannel(lastReleaseChannel, channel)) | ||||
|           ? semver.inc(lastRelease.version, 'prerelease') | ||||
|           : `${semver.inc(`${major}.${minor}.${patch}`, type)}-${branch.prerelease}.${FIRSTPRERELEASE}` | ||||
|         : semver.inc(lastRelease.version, type); | ||||
|  | ||||
							
								
								
									
										60
									
								
								lib/get-release-to-add.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								lib/get-release-to-add.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,60 @@ | ||||
| const {uniqBy, intersection} = require('lodash'); | ||||
| const semver = require('semver'); | ||||
| const semverDiff = require('semver-diff'); | ||||
| const getLastRelease = require('./get-last-release'); | ||||
| const {makeTag, getLowerBound} = require('./utils'); | ||||
| 
 | ||||
| /** | ||||
|  * Find releases that have been merged from from a higher branch but not added on the channel of the current branch. | ||||
|  * | ||||
|  * @param {Object} context semantic-release context. | ||||
|  * | ||||
|  * @return {Array<Object>} Last release and next release to be added on the channel of the current branch. | ||||
|  */ | ||||
| module.exports = context => { | ||||
|   const { | ||||
|     branch, | ||||
|     branches, | ||||
|     options: {tagFormat}, | ||||
|   } = context; | ||||
| 
 | ||||
|   const higherChannels = branches | ||||
|     // Consider only releases of higher branches
 | ||||
|     .slice(branches.findIndex(({name}) => name === branch.name) + 1) | ||||
|     // Exclude prerelease branches
 | ||||
|     .filter(({type}) => type !== 'prerelease') | ||||
|     .map(({channel}) => channel); | ||||
| 
 | ||||
|   const versiontoAdd = uniqBy( | ||||
|     branch.tags.filter( | ||||
|       ({channels, version}) => | ||||
|         !channels.includes(branch.channel) && | ||||
|         intersection(channels, higherChannels).length > 0 && | ||||
|         (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch.mergeRange))) | ||||
|     ), | ||||
|     'version' | ||||
|   ).sort((a, b) => semver.compare(b.version, a.version))[0]; | ||||
| 
 | ||||
|   if (versiontoAdd) { | ||||
|     const {version, gitTag, channels} = versiontoAdd; | ||||
|     const lastRelease = getLastRelease(context, {before: version}); | ||||
|     if (semver.gt(getLastRelease(context).version, version)) { | ||||
|       return; | ||||
|     } | ||||
| 
 | ||||
|     const type = lastRelease.version ? semverDiff(lastRelease.version, version) : 'major'; | ||||
|     const name = makeTag(tagFormat, version); | ||||
|     return { | ||||
|       lastRelease, | ||||
|       currentRelease: {type, version, channels, gitTag, name, gitHead: gitTag}, | ||||
|       nextRelease: { | ||||
|         type, | ||||
|         version, | ||||
|         channel: branch.channel, | ||||
|         gitTag: makeTag(tagFormat, version, branch.channel), | ||||
|         name, | ||||
|         gitHead: gitTag, | ||||
|       }, | ||||
|     }; | ||||
|   } | ||||
| }; | ||||
| @ -1,71 +0,0 @@ | ||||
| const {uniq} = require('lodash'); | ||||
| const semver = require('semver'); | ||||
| const semverDiff = require('semver-diff'); | ||||
| const getLastRelease = require('./get-last-release'); | ||||
| const {makeTag, getLowerBound} = require('./utils'); | ||||
| 
 | ||||
| /** | ||||
|  * Find releases that have been merged from from a higher branch but not added on the channel of the current branch. | ||||
|  * | ||||
|  * @param {Object} context semantic-release context. | ||||
|  * | ||||
|  * @return {Array<Object>} Last release and next release to be added on the channel of the current branch. | ||||
|  */ | ||||
| module.exports = context => { | ||||
|   const { | ||||
|     branch, | ||||
|     branches, | ||||
|     options: {tagFormat}, | ||||
|   } = context; | ||||
| 
 | ||||
|   return ( | ||||
|     branches | ||||
|       // Consider only releases of higher branches
 | ||||
|       .slice(branches.findIndex(({name}) => name === branch.name) + 1) | ||||
|       // Exclude prerelease branches
 | ||||
|       .filter(({type}) => type !== 'prerelease') | ||||
|       // Find higher branch releases merged to building branch but not released on associated channel
 | ||||
|       .reduce( | ||||
|         (releases, higherBranch) => [ | ||||
|           ...releases, | ||||
|           // For all unique release version of the higher branch merged on current branch, excluding lower than start range version for maintenance branches
 | ||||
|           ...uniq( | ||||
|             branch.tags.filter( | ||||
|               ({channel, version}) => | ||||
|                 channel === higherBranch.channel && | ||||
|                 channel !== branch.channel && | ||||
|                 (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch.mergeRange))) | ||||
|             ) | ||||
|           ) | ||||
|             // Find ones that are not released on the building branch channel
 | ||||
|             .filter(tag => | ||||
|               branch.tags.every( | ||||
|                 ({version, channel}) => | ||||
|                   version !== tag.version || channel === higherBranch.channel || channel !== branch.channel | ||||
|               ) | ||||
|             ) | ||||
|             // Sort in ascending order to add the most recent release last
 | ||||
|             .sort((a, b) => semver.compare(a.version, b.version)) | ||||
|             // Construct the last and next release to add to the building branch channel
 | ||||
|             .map(({version, gitTag}) => { | ||||
|               const lastRelease = getLastRelease(context, {before: version}); | ||||
|               const type = lastRelease.version ? semverDiff(lastRelease.version, version) : 'major'; | ||||
|               const name = makeTag(tagFormat, version); | ||||
|               return { | ||||
|                 lastRelease, | ||||
|                 currentRelease: {type, version, channel: higherBranch.channel, gitTag, name, gitHead: gitTag}, | ||||
|                 nextRelease: { | ||||
|                   type, | ||||
|                   version, | ||||
|                   channel: branch.channel, | ||||
|                   gitTag: makeTag(tagFormat, version, branch.channel), | ||||
|                   name, | ||||
|                   gitHead: gitTag, | ||||
|                 }, | ||||
|               }; | ||||
|             }), | ||||
|         ], | ||||
|         [] | ||||
|       ) | ||||
|   ); | ||||
| }; | ||||
| @ -20,9 +20,9 @@ test('Get the valid tags', async t => { | ||||
|     { | ||||
|       name: 'master', | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined}, | ||||
|         {gitTag: 'v3.0.0-beta.1', version: '3.0.0-beta.1', channel: undefined}, | ||||
|         {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]}, | ||||
|       ], | ||||
|     }, | ||||
|   ]); | ||||
| @ -55,23 +55,17 @@ test('Get the valid tags from multiple branches', async t => { | ||||
|     { | ||||
|       name: '1.x', | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channel: undefined}, | ||||
|         {gitTag: 'v1.0.0@1.x', version: '1.0.0', channel: '1.x'}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0', channel: undefined}, | ||||
|         {gitTag: 'v1.1.0@1.x', version: '1.1.0', channel: '1.x'}, | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, '1.x']}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined, '1.x']}, | ||||
|       ], | ||||
|     }, | ||||
|     { | ||||
|       name: 'master', | ||||
|       tags: [ | ||||
|         ...result[0].tags, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', channel: undefined}, | ||||
|         {gitTag: 'v2.0.0@next', version: '2.0.0', channel: 'next'}, | ||||
|       ], | ||||
|       tags: [...result[0].tags, {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined, 'next']}], | ||||
|     }, | ||||
|     { | ||||
|       name: 'next', | ||||
|       tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channel: 'next'}], | ||||
|       tags: [...result[1].tags, {gitTag: 'v3.0.0@next', version: '3.0.0', channels: ['next']}], | ||||
|     }, | ||||
|   ]); | ||||
| }); | ||||
| @ -91,10 +85,8 @@ test('Match the tag name from the begining of the string and the channel from th | ||||
|     { | ||||
|       name: 'master', | ||||
|       tags: [ | ||||
|         {gitTag: 'prefix@v1.0.0', version: '1.0.0', channel: undefined}, | ||||
|         {gitTag: 'prefix@v1.0.0@next', version: '1.0.0', channel: 'next'}, | ||||
|         {gitTag: 'prefix@v2.0.0', version: '2.0.0', channel: undefined}, | ||||
|         {gitTag: 'prefix@v2.0.0@next', version: '2.0.0', channel: 'next'}, | ||||
|         {gitTag: 'prefix@v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, | ||||
|         {gitTag: 'prefix@v2.0.0', version: '2.0.0', channels: [undefined, 'next']}, | ||||
|       ], | ||||
|     }, | ||||
|   ]); | ||||
| @ -141,19 +133,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', channel: undefined}]}, | ||||
|     {name: 'master', tags: [{gitTag: '1.0.0', version: '1.0.0', channels: [undefined]}]}, | ||||
|   ]); | ||||
| 
 | ||||
|   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', channel: undefined}]}, | ||||
|     {name: 'master', tags: [{gitTag: 'foo-1.0.0-bar', version: '1.0.0', channels: [undefined]}]}, | ||||
|   ]); | ||||
| 
 | ||||
|   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', channel: undefined}], | ||||
|       tags: [{gitTag: 'foo-v1.0.0-bar', version: '1.0.0', channels: [undefined]}], | ||||
|     }, | ||||
|   ]); | ||||
| 
 | ||||
| @ -161,7 +153,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', channel: undefined}], | ||||
|       tags: [{gitTag: '(.+)/1.0.0/(a-z)', version: '1.0.0', channels: [undefined]}], | ||||
|     }, | ||||
|   ]); | ||||
| 
 | ||||
| @ -169,12 +161,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', channel: undefined}], | ||||
|       tags: [{gitTag: '2.0.0-1.0.0-bar.1', version: '1.0.0', channels: [undefined]}], | ||||
|     }, | ||||
|   ]); | ||||
| 
 | ||||
|   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', channel: undefined}]}, | ||||
|     {name: 'master', tags: [{gitTag: '3.0.0-bar.2', version: '3.0.0', channels: [undefined]}]}, | ||||
|   ]); | ||||
| }); | ||||
|  | ||||
| @ -15,7 +15,7 @@ test('Get the highest non-prerelease valid tag', t => { | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channel: undefined}); | ||||
|   t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channels: undefined}); | ||||
| }); | ||||
| 
 | ||||
| test('Get the highest prerelease valid tag, ignoring other tags from other prerelease channels', t => { | ||||
| @ -25,9 +25,14 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere | ||||
|       prerelease: 'beta', | ||||
|       channel: 'beta', | ||||
|       tags: [ | ||||
|         {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: 'v1.0.0-beta.2@beta', channel: 'beta'}, | ||||
|         {version: '1.0.0-alpha.1', gitTag: 'v1.0.0-alpha.1@alpha', gitHead: 'v1.0.0-alpha.1@alpha', channel: 'alpha'}, | ||||
|         {version: '1.0.0-beta.1', gitTag: 'v1.0.0-beta.1@beta', gitHead: 'v1.0.0-beta.1@beta', channels: ['beta']}, | ||||
|         {version: '1.0.0-beta.2', gitTag: 'v1.0.0-beta.2@beta', gitHead: 'v1.0.0-beta.2@beta', channels: ['beta']}, | ||||
|         { | ||||
|           version: '1.0.0-alpha.1', | ||||
|           gitTag: 'v1.0.0-alpha.1@alpha', | ||||
|           gitHead: 'v1.0.0-alpha.1@alpha', | ||||
|           channels: ['alpha'], | ||||
|         }, | ||||
|       ], | ||||
|       type: 'prerelease', | ||||
|     }, | ||||
| @ -39,7 +44,7 @@ test('Get the highest prerelease valid tag, ignoring other tags from other prere | ||||
|     gitTag: 'v1.0.0-beta.2@beta', | ||||
|     name: 'v1.0.0-beta.2', | ||||
|     gitHead: 'v1.0.0-beta.2@beta', | ||||
|     channel: 'beta', | ||||
|     channels: ['beta'], | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| @ -76,5 +81,5 @@ test('Get the highest non-prerelease valid tag before a certain version', t => { | ||||
|     {before: '2.1.0'} | ||||
|   ); | ||||
| 
 | ||||
|   t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channel: undefined}); | ||||
|   t.deepEqual(result, {version: '2.0.0', gitTag: 'v2.0.0', name: 'v2.0.0', gitHead: 'v2.0.0', channels: undefined}); | ||||
| }); | ||||
|  | ||||
| @ -13,7 +13,7 @@ test('Increase version for patch release', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'master', type: 'release'}, | ||||
|       nextRelease: {type: 'patch'}, | ||||
|       lastRelease: {version: '1.0.0'}, | ||||
|       lastRelease: {version: '1.0.0', channels: [undefined]}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '1.0.1' | ||||
| @ -25,7 +25,7 @@ test('Increase version for minor release', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'master', type: 'release'}, | ||||
|       nextRelease: {type: 'minor'}, | ||||
|       lastRelease: {version: '1.0.0'}, | ||||
|       lastRelease: {version: '1.0.0', channels: [undefined]}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '1.1.0' | ||||
| @ -37,7 +37,7 @@ test('Increase version for major release', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'master', type: 'release'}, | ||||
|       nextRelease: {type: 'major'}, | ||||
|       lastRelease: {version: '1.0.0'}, | ||||
|       lastRelease: {version: '1.0.0', channels: [undefined]}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '2.0.0' | ||||
| @ -61,7 +61,7 @@ test('Increase version for patch release on prerelease branch', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, | ||||
|       nextRelease: {type: 'patch'}, | ||||
|       lastRelease: {version: '1.0.0'}, | ||||
|       lastRelease: {version: '1.0.0', channels: [undefined]}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '1.0.1-beta.1' | ||||
| @ -71,7 +71,7 @@ test('Increase version for patch release on prerelease branch', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, | ||||
|       nextRelease: {type: 'patch'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1', channels: [undefined]}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '1.0.0-beta.2' | ||||
| @ -81,7 +81,7 @@ test('Increase version for patch release on prerelease branch', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, | ||||
|       nextRelease: {type: 'patch', channel: 'alpha'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1', channel: 'beta'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1', channels: ['beta']}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '1.0.1-alpha.1' | ||||
| @ -93,7 +93,7 @@ test('Increase version for minor release on prerelease branch', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, | ||||
|       nextRelease: {type: 'minor'}, | ||||
|       lastRelease: {version: '1.0.0'}, | ||||
|       lastRelease: {version: '1.0.0', channels: [undefined]}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '1.1.0-beta.1' | ||||
| @ -103,7 +103,7 @@ test('Increase version for minor release on prerelease branch', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, | ||||
|       nextRelease: {type: 'minor'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1', channels: [undefined]}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '1.0.0-beta.2' | ||||
| @ -113,7 +113,7 @@ test('Increase version for minor release on prerelease branch', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, | ||||
|       nextRelease: {type: 'minor', channel: 'alpha'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1', channel: 'beta'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1', channels: ['beta']}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '1.1.0-alpha.1' | ||||
| @ -125,7 +125,7 @@ test('Increase version for major release on prerelease branch', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, | ||||
|       nextRelease: {type: 'major'}, | ||||
|       lastRelease: {version: '1.0.0'}, | ||||
|       lastRelease: {version: '1.0.0', channels: [undefined]}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '2.0.0-beta.1' | ||||
| @ -135,7 +135,7 @@ test('Increase version for major release on prerelease branch', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'beta', type: 'prerelease', prerelease: 'beta'}, | ||||
|       nextRelease: {type: 'major'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1', channels: [undefined]}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '1.0.0-beta.2' | ||||
| @ -145,7 +145,7 @@ test('Increase version for major release on prerelease branch', t => { | ||||
|     getNextVersion({ | ||||
|       branch: {name: 'alpha', type: 'prerelease', prerelease: 'alpha'}, | ||||
|       nextRelease: {type: 'major', channel: 'alpha'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1', channel: 'beta'}, | ||||
|       lastRelease: {version: '1.0.0-beta.1', channels: ['beta']}, | ||||
|       logger: t.context.logger, | ||||
|     }), | ||||
|     '2.0.0-alpha.1' | ||||
|  | ||||
							
								
								
									
										283
									
								
								test/get-release-to-add.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										283
									
								
								test/get-release-to-add.test.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,283 @@ | ||||
| import test from 'ava'; | ||||
| import getReleaseToAdd from '../lib/get-release-to-add'; | ||||
| 
 | ||||
| test('Return versions merged from release to maintenance branch, excluding lower than branch start range', t => { | ||||
|   const result = getReleaseToAdd({ | ||||
|     branch: { | ||||
|       name: '2.x', | ||||
|       channel: '2.x', | ||||
|       type: 'maintenance', | ||||
|       mergeRange: '>=2.0.0 <3.0.0', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0@2.x', version: '2.0.0', channels: ['2.x']}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, | ||||
|         {gitTag: 'v2.1.0', version: '2.1.0', channels: [undefined]}, | ||||
|         {gitTag: 'v2.1.1', version: '2.1.1', channels: [undefined]}, | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, { | ||||
|     lastRelease: {version: '2.1.0', channels: [undefined], gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: 'v2.1.0'}, | ||||
|     currentRelease: { | ||||
|       type: 'patch', | ||||
|       version: '2.1.1', | ||||
|       channels: [undefined], | ||||
|       gitTag: 'v2.1.1', | ||||
|       name: 'v2.1.1', | ||||
|       gitHead: 'v2.1.1', | ||||
|     }, | ||||
|     nextRelease: { | ||||
|       type: 'patch', | ||||
|       version: '2.1.1', | ||||
|       channel: '2.x', | ||||
|       gitTag: 'v2.1.1@2.x', | ||||
|       name: 'v2.1.1', | ||||
|       gitHead: 'v2.1.1', | ||||
|     }, | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| test('Return versions merged between release branches', t => { | ||||
|   const result = getReleaseToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, | ||||
|         {gitTag: 'v1.1.0@next', version: '1.1.0', channels: ['next']}, | ||||
|         {gitTag: 'v2.0.0@next-major', version: '2.0.0', channels: ['next-major']}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, { | ||||
|     lastRelease: { | ||||
|       version: '1.1.0', | ||||
|       gitTag: 'v1.1.0@next', | ||||
|       name: 'v1.1.0', | ||||
|       gitHead: 'v1.1.0@next', | ||||
|       channels: ['next'], | ||||
|     }, | ||||
|     currentRelease: { | ||||
|       type: 'major', | ||||
|       version: '2.0.0', | ||||
|       channels: ['next-major'], | ||||
|       gitTag: 'v2.0.0@next-major', | ||||
|       name: 'v2.0.0', | ||||
|       gitHead: 'v2.0.0@next-major', | ||||
|     }, | ||||
|     nextRelease: { | ||||
|       type: 'major', | ||||
|       version: '2.0.0', | ||||
|       channel: undefined, | ||||
|       gitTag: 'v2.0.0', | ||||
|       name: 'v2.0.0', | ||||
|       gitHead: 'v2.0.0@next-major', | ||||
|     }, | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| test('Return releases sorted by ascending order', t => { | ||||
|   const result = getReleaseToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0@next-major', version: '2.0.0', channels: ['next-major']}, | ||||
|         {gitTag: 'v1.1.0@next', version: '1.1.0', channels: ['next']}, | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, | ||||
|         // {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'},
 | ||||
|       ], | ||||
|     }, | ||||
|     branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, { | ||||
|     lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channels: ['next']}, | ||||
|     currentRelease: { | ||||
|       type: 'major', | ||||
|       version: '2.0.0', | ||||
|       channels: ['next-major'], | ||||
|       gitTag: 'v2.0.0@next-major', | ||||
|       name: 'v2.0.0', | ||||
|       gitHead: 'v2.0.0@next-major', | ||||
|     }, | ||||
|     nextRelease: { | ||||
|       type: 'major', | ||||
|       version: '2.0.0', | ||||
|       channel: undefined, | ||||
|       gitTag: 'v2.0.0', | ||||
|       name: 'v2.0.0', | ||||
|       gitHead: 'v2.0.0@next-major', | ||||
|     }, | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| test('No lastRelease', t => { | ||||
|   const result = getReleaseToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channels: ['next']}], | ||||
|     }, | ||||
|     branches: [{name: 'master'}, {name: 'next', channel: 'next'}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, { | ||||
|     lastRelease: {}, | ||||
|     currentRelease: { | ||||
|       type: 'major', | ||||
|       version: '1.0.0', | ||||
|       channels: ['next'], | ||||
|       gitTag: 'v1.0.0@next', | ||||
|       name: 'v1.0.0', | ||||
|       gitHead: 'v1.0.0@next', | ||||
|     }, | ||||
|     nextRelease: { | ||||
|       type: 'major', | ||||
|       version: '1.0.0', | ||||
|       channel: undefined, | ||||
|       gitTag: 'v1.0.0', | ||||
|       name: 'v1.0.0', | ||||
|       gitHead: 'v1.0.0@next', | ||||
|     }, | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| test('Ignore pre-release versions', t => { | ||||
|   const result = getReleaseToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined, 'next']}, | ||||
|         {gitTag: 'v1.1.0@next', version: '1.1.0', channels: ['next']}, | ||||
|         {gitTag: 'v2.0.0-alpha.1@alpha', version: '2.0.0-alpha.1', channels: ['alpha']}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [ | ||||
|       {name: 'master'}, | ||||
|       {name: 'next', channel: 'next'}, | ||||
|       {name: 'alpha', type: 'prerelease', channel: 'alpha'}, | ||||
|     ], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, { | ||||
|     lastRelease: {version: '1.0.0', channels: [undefined, 'next'], gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, | ||||
|     currentRelease: { | ||||
|       type: 'minor', | ||||
|       version: '1.1.0', | ||||
|       channels: ['next'], | ||||
|       gitTag: 'v1.1.0@next', | ||||
|       name: 'v1.1.0', | ||||
|       gitHead: 'v1.1.0@next', | ||||
|     }, | ||||
|     nextRelease: { | ||||
|       type: 'minor', | ||||
|       version: '1.1.0', | ||||
|       channel: undefined, | ||||
|       gitTag: 'v1.1.0', | ||||
|       name: 'v1.1.0', | ||||
|       gitHead: 'v1.1.0@next', | ||||
|     }, | ||||
|   }); | ||||
| }); | ||||
| 
 | ||||
| test('Exclude versions merged from release to maintenance branch if they have the same "channel"', t => { | ||||
|   const result = getReleaseToAdd({ | ||||
|     branch: { | ||||
|       name: '2.x', | ||||
|       channel: 'latest', | ||||
|       type: 'maintenance', | ||||
|       mergeRange: '>=2.0.0 <3.0.0', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, | ||||
|         {gitTag: 'v2.1.0', version: '2.1.0', channels: [undefined]}, | ||||
|         {gitTag: 'v2.1.1', version: '2.1.1', channels: [undefined]}, | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [ | ||||
|       {name: '2.x', channel: 'latest'}, | ||||
|       {name: 'master', channel: 'latest'}, | ||||
|     ], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.is(result, undefined); | ||||
| }); | ||||
| 
 | ||||
| test('Exclude versions merged between release branches if they have the same "channel"', t => { | ||||
|   const result = getReleaseToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       channel: 'latest', | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', channels: ['latest'], version: '1.0.0'}, | ||||
|         {gitTag: 'v1.1.0', channels: ['latest'], version: '1.1.0'}, | ||||
|         {gitTag: 'v2.0.0', channels: ['latest'], version: '2.0.0'}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [ | ||||
|       {name: 'master', channel: 'latest'}, | ||||
|       {name: 'next', channel: 'latest'}, | ||||
|       {name: 'next-major', channel: 'latest'}, | ||||
|     ], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.is(result, undefined); | ||||
| }); | ||||
| 
 | ||||
| test('Exclude versions merged between release branches if they all have "channel" set to "false"', t => { | ||||
|   const result = getReleaseToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       channel: false, | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [ | ||||
|       {name: 'master', channel: false}, | ||||
|       {name: 'next', channel: false}, | ||||
|       {name: 'next-major', channel: false}, | ||||
|     ], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.is(result, undefined); | ||||
| }); | ||||
| 
 | ||||
| test('Exclude versions number less than the latest version already released on that branch', t => { | ||||
|   const result = getReleaseToAdd({ | ||||
|     branch: { | ||||
|       name: '2.x', | ||||
|       channel: '2.x', | ||||
|       type: 'maintenance', | ||||
|       mergeRange: '>=2.0.0 <3.0.0', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0@2.x', version: '2.0.0', channels: ['2.x']}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', channels: [undefined]}, | ||||
|         {gitTag: 'v2.1.0', version: '2.1.0', channels: [undefined]}, | ||||
|         {gitTag: 'v2.1.1', version: '2.1.1', channels: [undefined, '2.x']}, | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', channels: [undefined]}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0', channels: [undefined]}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.is(result, undefined); | ||||
| }); | ||||
| @ -1,323 +0,0 @@ | ||||
| import test from 'ava'; | ||||
| import getReleasesToAdd from '../lib/get-releases-to-add'; | ||||
| 
 | ||||
| test('Return versions merged from release to maintenance branch, excluding lower than branch start range', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: { | ||||
|       name: '2.x', | ||||
|       channel: '2.x', | ||||
|       type: 'maintenance', | ||||
|       mergeRange: '>=2.0.0 <3.0.0', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0@2.x', version: '2.0.0', channel: '2.x'}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0'}, | ||||
|         {gitTag: 'v2.1.0', version: '2.1.0'}, | ||||
|         {gitTag: 'v2.1.1', version: '2.1.1'}, | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0'}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0'}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [{name: '2.x', channel: '2.x'}, {name: 'master'}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, [ | ||||
|     { | ||||
|       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: { | ||||
|         type: 'minor', | ||||
|         version: '2.1.0', | ||||
|         channel: undefined, | ||||
|         gitTag: 'v2.1.0', | ||||
|         name: 'v2.1.0', | ||||
|         gitHead: 'v2.1.0', | ||||
|       }, | ||||
|       nextRelease: { | ||||
|         type: 'minor', | ||||
|         version: '2.1.0', | ||||
|         channel: '2.x', | ||||
|         gitTag: 'v2.1.0@2.x', | ||||
|         name: 'v2.1.0', | ||||
|         gitHead: 'v2.1.0', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       lastRelease: {version: '2.1.0', channel: undefined, gitTag: 'v2.1.0', name: 'v2.1.0', gitHead: 'v2.1.0'}, | ||||
|       currentRelease: { | ||||
|         type: 'patch', | ||||
|         version: '2.1.1', | ||||
|         channel: undefined, | ||||
|         gitTag: 'v2.1.1', | ||||
|         name: 'v2.1.1', | ||||
|         gitHead: 'v2.1.1', | ||||
|       }, | ||||
|       nextRelease: { | ||||
|         type: 'patch', | ||||
|         version: '2.1.1', | ||||
|         channel: '2.x', | ||||
|         gitTag: 'v2.1.1@2.x', | ||||
|         name: 'v2.1.1', | ||||
|         gitHead: 'v2.1.1', | ||||
|       }, | ||||
|     }, | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
| test('Return versions merged between release branches', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0'}, | ||||
|         {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, | ||||
|         {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'}, | ||||
|         {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'}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, [ | ||||
|     { | ||||
|       lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, | ||||
|       currentRelease: { | ||||
|         type: 'minor', | ||||
|         version: '1.1.0', | ||||
|         channel: 'next', | ||||
|         gitTag: 'v1.1.0@next', | ||||
|         name: 'v1.1.0', | ||||
|         gitHead: 'v1.1.0@next', | ||||
|       }, | ||||
|       nextRelease: { | ||||
|         type: 'minor', | ||||
|         version: '1.1.0', | ||||
|         channel: undefined, | ||||
|         gitTag: 'v1.1.0', | ||||
|         name: 'v1.1.0', | ||||
|         gitHead: 'v1.1.0@next', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channel: 'next'}, | ||||
|       currentRelease: { | ||||
|         type: 'major', | ||||
|         version: '2.0.0', | ||||
|         channel: 'next-major', | ||||
|         gitTag: 'v2.0.0@next-major', | ||||
|         name: 'v2.0.0', | ||||
|         gitHead: 'v2.0.0@next-major', | ||||
|       }, | ||||
|       nextRelease: { | ||||
|         type: 'major', | ||||
|         version: '2.0.0', | ||||
|         channel: undefined, | ||||
|         gitTag: 'v2.0.0', | ||||
|         name: 'v2.0.0', | ||||
|         gitHead: 'v2.0.0@next-major', | ||||
|       }, | ||||
|     }, | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
| test('Return releases sorted by ascending order', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0@next-major', version: '2.0.0', channel: 'next-major'}, | ||||
|         {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'}, | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0'}, | ||||
|         {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [{name: 'master'}, {name: 'next', channel: 'next'}, {name: 'next-major', channel: 'next-major'}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, [ | ||||
|     { | ||||
|       lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, | ||||
|       currentRelease: { | ||||
|         type: 'minor', | ||||
|         version: '1.1.0', | ||||
|         channel: 'next', | ||||
|         gitTag: 'v1.1.0@next', | ||||
|         name: 'v1.1.0', | ||||
|         gitHead: 'v1.1.0@next', | ||||
|       }, | ||||
|       nextRelease: { | ||||
|         type: 'minor', | ||||
|         version: '1.1.0', | ||||
|         channel: undefined, | ||||
|         gitTag: 'v1.1.0', | ||||
|         name: 'v1.1.0', | ||||
|         gitHead: 'v1.1.0@next', | ||||
|       }, | ||||
|     }, | ||||
|     { | ||||
|       lastRelease: {version: '1.1.0', gitTag: 'v1.1.0@next', name: 'v1.1.0', gitHead: 'v1.1.0@next', channel: 'next'}, | ||||
|       currentRelease: { | ||||
|         type: 'major', | ||||
|         version: '2.0.0', | ||||
|         channel: 'next-major', | ||||
|         gitTag: 'v2.0.0@next-major', | ||||
|         name: 'v2.0.0', | ||||
|         gitHead: 'v2.0.0@next-major', | ||||
|       }, | ||||
|       nextRelease: { | ||||
|         type: 'major', | ||||
|         version: '2.0.0', | ||||
|         channel: undefined, | ||||
|         gitTag: 'v2.0.0', | ||||
|         name: 'v2.0.0', | ||||
|         gitHead: 'v2.0.0@next-major', | ||||
|       }, | ||||
|     }, | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
| test('No lastRelease', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}], | ||||
|     }, | ||||
|     branches: [{name: 'master'}, {name: 'next', channel: 'next'}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, [ | ||||
|     { | ||||
|       lastRelease: {}, | ||||
|       currentRelease: { | ||||
|         type: 'major', | ||||
|         version: '1.0.0', | ||||
|         channel: 'next', | ||||
|         gitTag: 'v1.0.0@next', | ||||
|         name: 'v1.0.0', | ||||
|         gitHead: 'v1.0.0@next', | ||||
|       }, | ||||
|       nextRelease: { | ||||
|         type: 'major', | ||||
|         version: '1.0.0', | ||||
|         channel: undefined, | ||||
|         gitTag: 'v1.0.0', | ||||
|         name: 'v1.0.0', | ||||
|         gitHead: 'v1.0.0@next', | ||||
|       }, | ||||
|     }, | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
| test('Ignore pre-release versions', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0'}, | ||||
|         {gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next'}, | ||||
|         {gitTag: 'v1.1.0@next', version: '1.1.0', channel: 'next'}, | ||||
|         {gitTag: 'v2.0.0-alpha.1@alpha', version: '2.0.0', channel: 'alpha'}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [ | ||||
|       {name: 'master'}, | ||||
|       {name: 'next', channel: 'next'}, | ||||
|       {name: 'alpha', type: 'prerelease', channel: 'alpha'}, | ||||
|     ], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, [ | ||||
|     { | ||||
|       lastRelease: {version: '1.0.0', channel: undefined, gitTag: 'v1.0.0', name: 'v1.0.0', gitHead: 'v1.0.0'}, | ||||
|       currentRelease: { | ||||
|         type: 'minor', | ||||
|         version: '1.1.0', | ||||
|         channel: 'next', | ||||
|         gitTag: 'v1.1.0@next', | ||||
|         name: 'v1.1.0', | ||||
|         gitHead: 'v1.1.0@next', | ||||
|       }, | ||||
|       nextRelease: { | ||||
|         type: 'minor', | ||||
|         version: '1.1.0', | ||||
|         channel: undefined, | ||||
|         gitTag: 'v1.1.0', | ||||
|         name: 'v1.1.0', | ||||
|         gitHead: 'v1.1.0@next', | ||||
|       }, | ||||
|     }, | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
| test('Exclude versions merged from release to maintenance branch if they have the same "channel"', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: { | ||||
|       name: '2.x', | ||||
|       channel: 'latest', | ||||
|       type: 'maintenance', | ||||
|       mergeRange: '>=2.0.0 <3.0.0', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0'}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0'}, | ||||
|         {gitTag: 'v2.1.0', version: '2.1.0'}, | ||||
|         {gitTag: 'v2.1.1', version: '2.1.1'}, | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0'}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0'}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [ | ||||
|       {name: '2.x', channel: 'latest'}, | ||||
|       {name: 'master', channel: 'latest'}, | ||||
|     ], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, []); | ||||
| }); | ||||
| 
 | ||||
| test('Exclude versions merged between release branches if they have the same "channel"', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       channel: 'latest', | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', channel: 'latest', version: '1.0.0'}, | ||||
|         {gitTag: 'v1.1.0', channel: 'latest', version: '1.1.0'}, | ||||
|         {gitTag: 'v2.0.0', channel: 'latest', version: '2.0.0'}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [ | ||||
|       {name: 'master', channel: 'latest'}, | ||||
|       {name: 'next', channel: 'latest'}, | ||||
|       {name: 'next-major', channel: 'latest'}, | ||||
|     ], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, []); | ||||
| }); | ||||
| 
 | ||||
| test('Exclude versions merged between release branches if they all have "channel" set to "false"', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
|       channel: false, | ||||
|       tags: [ | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0'}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0'}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0'}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [ | ||||
|       {name: 'master', channel: false}, | ||||
|       {name: 'next', channel: false}, | ||||
|       {name: 'next-major', channel: false}, | ||||
|     ], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, []); | ||||
| }); | ||||
| @ -1,5 +1,5 @@ | ||||
| import test from 'ava'; | ||||
| import {escapeRegExp, isString, sortBy} from 'lodash'; | ||||
| import {escapeRegExp, isString, sortBy, omit} from 'lodash'; | ||||
| import proxyquire from 'proxyquire'; | ||||
| import {spy, stub} from 'sinon'; | ||||
| import {WritableStreamBuffer} from 'stream-buffers'; | ||||
| @ -57,7 +57,7 @@ test('Plugins are called with expected values', async t => { | ||||
|     gitHead: commits[commits.length - 1].hash, | ||||
|     gitTag: 'v1.0.0@next', | ||||
|     name: 'v1.0.0', | ||||
|     channel: 'next', | ||||
|     channels: ['next'], | ||||
|   }; | ||||
|   const nextRelease = { | ||||
|     name: 'v1.1.0', | ||||
| @ -96,7 +96,7 @@ test('Plugins are called with expected values', async t => { | ||||
|       name: 'master', | ||||
|       range: '>=1.0.0 <2.0.0', | ||||
|       accept: ['patch', 'minor'], | ||||
|       tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0'}], | ||||
|       tags: [{channels: ['next'], gitTag: 'v1.0.0@next', version: '1.0.0'}], | ||||
|       type: 'release', | ||||
|     }, | ||||
|     { | ||||
| @ -104,7 +104,7 @@ test('Plugins are called with expected values', async t => { | ||||
|       name: 'next', | ||||
|       range: '>=2.0.0', | ||||
|       accept: ['patch', 'minor', 'major'], | ||||
|       tags: [{channel: 'next', gitTag: 'v1.0.0@next', version: '1.0.0'}], | ||||
|       tags: [{channels: ['next'], gitTag: 'v1.0.0@next', version: '1.0.0'}], | ||||
|       type: 'release', | ||||
|     }, | ||||
|   ]; | ||||
| @ -124,7 +124,7 @@ test('Plugins are called with expected values', async t => { | ||||
| 
 | ||||
|   const releases = [ | ||||
|     { | ||||
|       ...lastRelease, | ||||
|       ...omit(lastRelease, 'channels'), | ||||
|       ...release1, | ||||
|       type: 'major', | ||||
|       version: '1.0.0', | ||||
| @ -176,7 +176,7 @@ test('Plugins are called with expected values', async t => { | ||||
|   t.deepEqual(generateNotes1.args[0][1].commits[0].hash, commits[1].hash); | ||||
|   t.deepEqual(generateNotes1.args[0][1].commits[0].message, commits[1].message); | ||||
|   t.deepEqual(generateNotes1.args[0][1].nextRelease, { | ||||
|     ...lastRelease, | ||||
|     ...omit(lastRelease, 'channels'), | ||||
|     type: 'major', | ||||
|     version: '1.0.0', | ||||
|     channel: undefined, | ||||
| @ -193,7 +193,7 @@ test('Plugins are called with expected values', async t => { | ||||
|   t.deepEqual(generateNotes2.args[0][1].commits[0].hash, commits[1].hash); | ||||
|   t.deepEqual(generateNotes2.args[0][1].commits[0].message, commits[1].message); | ||||
|   t.deepEqual(generateNotes2.args[0][1].nextRelease, { | ||||
|     ...lastRelease, | ||||
|     ...omit(lastRelease, 'channels'), | ||||
|     type: 'major', | ||||
|     version: '1.0.0', | ||||
|     channel: undefined, | ||||
| @ -211,7 +211,7 @@ test('Plugins are called with expected values', async t => { | ||||
|   t.deepEqual(generateNotes3.args[0][1].commits[0].hash, commits[1].hash); | ||||
|   t.deepEqual(generateNotes3.args[0][1].commits[0].message, commits[1].message); | ||||
|   t.deepEqual(generateNotes3.args[0][1].nextRelease, { | ||||
|     ...lastRelease, | ||||
|     ...omit(lastRelease, 'channels'), | ||||
|     type: 'major', | ||||
|     version: '1.0.0', | ||||
|     channel: undefined, | ||||
| @ -236,7 +236,7 @@ test('Plugins are called with expected values', async t => { | ||||
|   t.deepEqual(addChannel.args[0][1].lastRelease, {}); | ||||
|   t.deepEqual(addChannel.args[0][1].currentRelease, {...lastRelease, type: 'major'}); | ||||
|   t.deepEqual(addChannel.args[0][1].nextRelease, { | ||||
|     ...lastRelease, | ||||
|     ...omit(lastRelease, 'channels'), | ||||
|     type: 'major', | ||||
|     version: '1.0.0', | ||||
|     channel: undefined, | ||||
| @ -330,7 +330,7 @@ test('Plugins are called with expected values', async t => { | ||||
|   t.deepEqual(success.args[0][1].commits[0].hash, commits[1].hash); | ||||
|   t.deepEqual(success.args[0][1].commits[0].message, commits[1].message); | ||||
|   t.deepEqual(success.args[0][1].nextRelease, { | ||||
|     ...lastRelease, | ||||
|     ...omit(lastRelease, 'channels'), | ||||
|     type: 'major', | ||||
|     version: '1.0.0', | ||||
|     channel: undefined, | ||||
| @ -782,14 +782,6 @@ async function addChannelMacro(t, mergeFunction) { | ||||
|     publish, | ||||
|     success, | ||||
|   }; | ||||
|   const nextRelease1 = { | ||||
|     name: 'v2.0.0', | ||||
|     type: 'major', | ||||
|     version: '2.0.0', | ||||
|     channel: undefined, | ||||
|     gitTag: 'v2.0.0', | ||||
|     gitHead: commits[1].hash, | ||||
|   }; | ||||
|   const nextRelease2 = { | ||||
|     name: 'v2.0.1', | ||||
|     type: 'patch', | ||||
| @ -806,15 +798,11 @@ async function addChannelMacro(t, mergeFunction) { | ||||
|   const result = await semanticRelease(options, {cwd, env: {}, stdout: {write: () => {}}, stderr: {write: () => {}}}); | ||||
| 
 | ||||
|   t.deepEqual(result.releases, [ | ||||
|     {...nextRelease1, ...release1, notes, pluginName: '[Function: functionStub]'}, | ||||
|     {...nextRelease1, notes, pluginName: '[Function: functionStub]'}, | ||||
|     {...nextRelease2, ...release1, notes, pluginName: '[Function: functionStub]'}, | ||||
|     {...nextRelease2, notes, pluginName: '[Function: functionStub]'}, | ||||
|   ]); | ||||
| 
 | ||||
|   // Verify the tag has been created on the local and remote repo and reference
 | ||||
|   t.is(await gitTagHead(nextRelease1.gitTag, {cwd}), nextRelease1.gitHead); | ||||
|   t.is(await gitRemoteTagHead(repositoryUrl, nextRelease1.gitTag, {cwd}), nextRelease1.gitHead); | ||||
|   t.is(await gitTagHead(nextRelease2.gitTag, {cwd}), nextRelease2.gitHead); | ||||
|   t.is(await gitRemoteTagHead(repositoryUrl, nextRelease2.gitTag, {cwd}), nextRelease2.gitHead); | ||||
| } | ||||
| @ -1490,15 +1478,6 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma | ||||
|     fail, | ||||
|   }; | ||||
| 
 | ||||
|   const nextRelease = { | ||||
|     type: 'patch', | ||||
|     version: '1.1.1', | ||||
|     channel: '1.1.x', | ||||
|     gitTag: 'v1.1.1@1.1.x', | ||||
|     name: 'v1.1.1', | ||||
|     gitHead: commits[2].hash, | ||||
|   }; | ||||
| 
 | ||||
|   const semanticRelease = proxyquire('..', { | ||||
|     './lib/logger': t.context.logger, | ||||
|     'env-ci': () => ({isCi: true, branch: '1.1.x', isPr: false}), | ||||
| @ -1509,13 +1488,11 @@ test('Throws "EINVALIDMAINTENANCEMERGE" if merge an out of range release in a ma | ||||
|     )), | ||||
|   ]; | ||||
| 
 | ||||
|   t.is(addChannel.callCount, 1); | ||||
|   t.deepEqual(addChannel.args[0][1].nextRelease, {...nextRelease, notes}); | ||||
|   t.is(addChannel.callCount, 0); | ||||
| 
 | ||||
|   t.is(publish.callCount, 0); | ||||
| 
 | ||||
|   t.is(success.callCount, 1); | ||||
|   t.deepEqual(success.args[0][1].releases, [{...nextRelease, notes, pluginName: '[Function: functionStub]'}]); | ||||
|   t.is(success.callCount, 0); | ||||
| 
 | ||||
|   t.is(fail.callCount, 1); | ||||
|   t.deepEqual(fail.args[0][1].errors, errors); | ||||
|  | ||||
| @ -269,7 +269,7 @@ test('Release patch, minor and major versions', async t => { | ||||
|   const updateReleaseMock = await mockServer.mock( | ||||
|     `/repos/${owner}/${packageName}/releases/${releaseId}`, | ||||
|     { | ||||
|       body: {tag_name: `v${version}`, name: `v${version}`, prerelease: false}, | ||||
|       body: {name: `v${version}`, prerelease: false}, | ||||
|       headers: [{name: 'Authorization', values: [`token ${env.GH_TOKEN}`]}], | ||||
|     }, | ||||
|     {body: {html_url: `release-url/${version}`}, method: 'PATCH'} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user