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:
Pierre Vanduynslager
2019-11-27 15:18:23 -05:00
parent 5744c5ecd2
commit aec96c791f
13 changed files with 440 additions and 503 deletions
+15 -4
View File
@@ -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}];