From 4aad9cd49031a849216e71a1ce358ad0668e4d54 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 18 Dec 2018 01:53:09 -0500 Subject: [PATCH] fix: do not call `addChannel`for 2 merged branches configured with the same channel --- docs/usage/workflow-configuration.md | 12 ++--- lib/branches/normalize.js | 8 ++-- lib/get-releases-to-add.js | 1 + test/branches/normalize.test.js | 29 ++++++++++-- test/get-releases-to-add.test.js | 67 +++++++++++++++++++++++++++- test/utils.test.js | 2 + 6 files changed, 104 insertions(+), 15 deletions(-) diff --git a/docs/usage/workflow-configuration.md b/docs/usage/workflow-configuration.md index 81797f3d6c..eef0a826f9 100644 --- a/docs/usage/workflow-configuration.md +++ b/docs/usage/workflow-configuration.md @@ -20,12 +20,12 @@ 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. | -| `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). | - | +| 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. 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). | - | ### name diff --git a/lib/branches/normalize.js b/lib/branches/normalize.js index 34e4049e0b..dfd4ef86c4 100644 --- a/lib/branches/normalize.js +++ b/lib/branches/normalize.js @@ -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, diff --git a/lib/get-releases-to-add.js b/lib/get-releases-to-add.js index 8b6237dbfb..5bedcb1227 100644 --- a/lib/get-releases-to-add.js +++ b/lib/get-releases-to-add.js @@ -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']))) ) ) diff --git a/test/branches/normalize.test.js b/test/branches/normalize.test.js index cb4a7b36b9..c77c7babf5 100644 --- a/test/branches/normalize.test.js +++ b/test/branches/normalize.test.js @@ -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}, + ]); +}); diff --git a/test/get-releases-to-add.test.js b/test/get-releases-to-add.test.js index 5c78187e0a..521b099e6c 100644 --- a/test/get-releases-to-add.test.js +++ b/test/get-releases-to-add.test.js @@ -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, []); +}); diff --git a/test/utils.test.js b/test/utils.test.js index 8d5c630028..08b4ebd97c 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -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'); });