fix: do not call addChannelfor 2 merged branches configured with the same channel
				
					
				
			This commit is contained in:
		
							parent
							
								
									390e966341
								
							
						
					
					
						commit
						4aad9cd490
					
				| @ -21,9 +21,9 @@ The type of the branch is automatically determined based on naming convention an | ||||
| ## Branches properties | ||||
| 
 | ||||
| | Property     | Branch type                               | Description                                                                                                                                                                             | Default                                                                                         | | ||||
| |--------------|-------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------| | ||||
| |--------------|-------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------| | ||||
| | `name`       | All                                       | **Required.** The Git branch holding the commits to analyze and the code to release. See [name](#name).                                                                                 | - The value itself if defined as a `String` or the matching branches name if defined as a glob. | | ||||
| | `channel`    | All                                       | The distribution channel on which to publish releases from this branch. See [channel](#channel).                                                                                      | `undefined` for the first release branch, the value of `name` for subsequent ones.              | | ||||
| | `channel`    | All                                       | The distribution channel on which to publish releases from this branch. Set to `false` to force the default distribution channel instead of using the default. See [channel](#channel). | `undefined` for the first release branch, the value of `name` for subsequent ones.              | | ||||
| | `range`      | [maintenance](#maintenance-branches) only | **Required unless `name` is formatted like `N.N.x` or `N.x` (`N` is a number).** The range of [semantic versions](https://semver.org) to support on this branch. See [range](#range).   | The value of `name`.                                                                            | | ||||
| | `prerelease` | [pre-release](#pre-release-branches) only | **Required.** The pre-release detonation to append to [semantic versions](https://semver.org) released from this branch. See [prerelease](#prerelease).                                 | -                                                                                               | | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| const {sortBy} = require('lodash'); | ||||
| const {sortBy, isNil} = require('lodash'); | ||||
| const semver = require('semver'); | ||||
| const semverDiff = require('semver-diff'); | ||||
| const {FIRST_RELEASE, RELEASE_TYPE} = require('../definitions/constants'); | ||||
| @ -20,7 +20,7 @@ function maintenance({maintenance, release}) { | ||||
|       ...rest, | ||||
|       name, | ||||
|       range: range || name, | ||||
|       channel: channel || name, | ||||
|       channel: isNil(channel) ? name : channel, | ||||
|     })), | ||||
|     'range' | ||||
|   ).map(({name, range, tags, ...rest}, idx, branches) => { | ||||
| @ -83,7 +83,7 @@ function release({release}) { | ||||
|     const diff = bound ? semverDiff(min, bound) : null; | ||||
|     return { | ||||
|       ...rest, | ||||
|       channel: idx === 0 ? channel : channel || name, | ||||
|       channel: idx === 0 ? channel : isNil(channel) ? name : channel, | ||||
|       tags, | ||||
|       type: 'release', | ||||
|       name, | ||||
| @ -98,7 +98,7 @@ function prerelease({prerelease}) { | ||||
|     const preid = prerelease === true ? name : prerelease; | ||||
|     return { | ||||
|       ...rest, | ||||
|       channel: channel || name, | ||||
|       channel: isNil(channel) ? name : channel, | ||||
|       type: 'prerelease', | ||||
|       name, | ||||
|       prerelease: preid, | ||||
|  | ||||
| @ -33,6 +33,7 @@ module.exports = context => { | ||||
|             branch.tags.filter( | ||||
|               ({channel, version}) => | ||||
|                 channel === higherBranch.channel && | ||||
|                 channel !== branch.channel && | ||||
|                 (branch.type !== 'maintenance' || semver.gte(version, getLowerBound(branch['merge-range']))) | ||||
|             ) | ||||
|           ) | ||||
|  | ||||
| @ -4,7 +4,7 @@ import normalize from '../../lib/branches/normalize'; | ||||
| const toTags = versions => versions.map(version => ({version})); | ||||
| 
 | ||||
| test('Maintenance branches - initial state', t => { | ||||
|   const maintenance = [{name: '1.x', tags: []}, {name: '1.1.x', tags: []}, {name: '1.2.x', tags: []}]; | ||||
|   const maintenance = [{name: '1.x', channel: '1.x', tags: []}, {name: '1.1.x', tags: []}, {name: '1.2.x', tags: []}]; | ||||
|   const release = [{name: 'master', tags: []}]; | ||||
|   t.deepEqual( | ||||
|     normalize | ||||
| @ -148,7 +148,11 @@ test('Maintenance branches - cap range to default branch last release if all rel | ||||
| }); | ||||
| 
 | ||||
| test('Release branches - initial state', t => { | ||||
|   const release = [{name: 'master', tags: []}, {name: 'next', tags: []}, {name: 'next-major', tags: []}]; | ||||
|   const release = [ | ||||
|     {name: 'master', tags: []}, | ||||
|     {name: 'next', channel: 'next', tags: []}, | ||||
|     {name: 'next-major', tags: []}, | ||||
|   ]; | ||||
| 
 | ||||
|   t.deepEqual( | ||||
|     normalize.release({release}).map(({type, name, range, accept, channel}) => ({type, name, range, accept, channel})), | ||||
| @ -298,10 +302,29 @@ test('Release branches - limit releases on 2nd and 3rd branche based on 1st bran | ||||
| }); | ||||
| 
 | ||||
| test('Prerelease branches', t => { | ||||
|   const prerelease = [{name: 'beta', prerelease: true, tags: []}, {name: 'alpha', prerelease: 'preview', tags: []}]; | ||||
|   const prerelease = [ | ||||
|     {name: 'beta', channel: 'beta', prerelease: true, tags: []}, | ||||
|     {name: 'alpha', prerelease: 'preview', tags: []}, | ||||
|   ]; | ||||
| 
 | ||||
|   t.deepEqual(normalize.prerelease({prerelease}).map(({type, name, channel}) => ({type, name, channel})), [ | ||||
|     {type: 'prerelease', name: 'beta', channel: 'beta'}, | ||||
|     {type: 'prerelease', name: 'alpha', channel: 'alpha'}, | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
| test('Allow to set channel to "false" to prevent default', t => { | ||||
|   const maintenance = [{name: '1.x', channel: false, tags: []}]; | ||||
|   const release = [{name: 'master', channel: false, tags: []}, {name: 'next', channel: false, tags: []}]; | ||||
|   const prerelease = [{name: 'beta', channel: false, prerelease: true, tags: []}]; | ||||
|   t.deepEqual(normalize.maintenance({maintenance, release}).map(({name, channel}) => ({name, channel})), [ | ||||
|     {name: '1.x', channel: false}, | ||||
|   ]); | ||||
|   t.deepEqual(normalize.release({release}).map(({name, channel}) => ({name, channel})), [ | ||||
|     {name: 'master', channel: false}, | ||||
|     {name: 'next', channel: false}, | ||||
|   ]); | ||||
|   t.deepEqual(normalize.prerelease({prerelease}).map(({name, channel}) => ({name, channel})), [ | ||||
|     {name: 'beta', channel: false}, | ||||
|   ]); | ||||
| }); | ||||
|  | ||||
| @ -63,7 +63,7 @@ test('Return versions merged from release to maintenance branch, excluding lower | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
| test('Return versions merged from future branch to release branch', t => { | ||||
| test('Return versions merged between release branches', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: { | ||||
|       name: 'master', | ||||
| @ -177,7 +177,7 @@ test('Return releases sorted by ascending order', t => { | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
| test('no lastRelease', t => { | ||||
| test('No lastRelease', t => { | ||||
|   const result = getReleasesToAdd({ | ||||
|     branch: {name: 'master', tags: [{gitTag: 'v1.0.0@next', version: '1.0.0', channel: 'next', gitHead: '111'}]}, | ||||
|     branches: [{name: 'master'}, {name: 'next', channel: 'next'}], | ||||
| @ -248,3 +248,66 @@ test('Ignore pre-release versions', t => { | ||||
|     }, | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
| 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', | ||||
|       'merge-range': '>=2.0.0 <3.0.0', | ||||
|       tags: [ | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '111'}, | ||||
|         {gitTag: 'v2.1.0', version: '2.1.0', gitHead: '222'}, | ||||
|         {gitTag: 'v2.1.1', version: '2.1.1', gitHead: '333'}, | ||||
|         {gitTag: 'v1.0.0', version: '1.0.0', gitHead: '444'}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '555'}, | ||||
|       ], | ||||
|     }, | ||||
|     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', gitHead: '111'}, | ||||
|         {gitTag: 'v1.1.0', channel: 'latest', version: '1.1.0', gitHead: '222'}, | ||||
|         {gitTag: 'v2.0.0', channel: 'latest', version: '2.0.0', gitHead: '333'}, | ||||
|       ], | ||||
|     }, | ||||
|     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', gitHead: '111'}, | ||||
|         {gitTag: 'v1.1.0', version: '1.1.0', gitHead: '222'}, | ||||
|         {gitTag: 'v2.0.0', version: '2.0.0', gitHead: '333'}, | ||||
|       ], | ||||
|     }, | ||||
|     branches: [{name: 'master', channel: false}, {name: 'next', channel: false}, {name: 'next-major', channel: false}], | ||||
|     options: {tagFormat: `v\${version}`}, | ||||
|   }); | ||||
| 
 | ||||
|   t.deepEqual(result, []); | ||||
| }); | ||||
|  | ||||
| @ -173,6 +173,8 @@ test('getRange', t => { | ||||
| 
 | ||||
| test('makeTag', t => { | ||||
|   t.is(makeTag(`v\${version}`, '1.0.0'), 'v1.0.0'); | ||||
|   t.is(makeTag(`v\${version}`, '1.0.0', false), 'v1.0.0'); | ||||
|   t.is(makeTag(`v\${version}`, '1.0.0', null), 'v1.0.0'); | ||||
|   t.is(makeTag(`v\${version}`, '1.0.0', 'next'), 'v1.0.0@next'); | ||||
|   t.is(makeTag(`v\${version}@test`, '1.0.0', 'next'), 'v1.0.0@next@test'); | ||||
| }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user