perf: use git tag --merge <branch> to filter tags present in a branch history
BREAKING CHANGE: Git CLI version 2.7.1 or higher is now required The `--merge` option of the `git tag` command has been added in Git version 2.7.1 and is now used by semantic-release
This commit is contained in:
@@ -2,7 +2,7 @@ const {template, escapeRegExp} = require('lodash');
|
||||
const semver = require('semver');
|
||||
const pReduce = require('p-reduce');
|
||||
const debug = require('debug')('semantic-release:get-tags');
|
||||
const {getTags, isRefInHistory, getTagHead} = require('../../lib/git');
|
||||
const {getTags, getTagHead} = require('../../lib/git');
|
||||
|
||||
module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
|
||||
// Generate a regex to parse tags formatted with `tagFormat`
|
||||
@@ -10,25 +10,18 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
|
||||
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
|
||||
// so it's guaranteed to no be present in the `tagFormat`.
|
||||
const tagRegexp = `^${escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.[^@]+)@?(.+)?')}`;
|
||||
const tags = (await getTags({cwd, env}))
|
||||
.map(tag => {
|
||||
const [, version, channel] = tag.match(tagRegexp) || [];
|
||||
return {gitTag: tag, version, channel};
|
||||
})
|
||||
.filter(({version}) => version && semver.valid(semver.clean(version)));
|
||||
|
||||
debug('found tags: %o', tags);
|
||||
|
||||
return pReduce(
|
||||
branches,
|
||||
async (branches, branch) => {
|
||||
const branchTags = await pReduce(
|
||||
tags,
|
||||
async (tags, {gitTag, ...rest}) =>
|
||||
(await isRefInHistory(gitTag, branch.name, {cwd, env}))
|
||||
? [...tags, {...rest, gitTag, gitHead: await getTagHead(gitTag, {cwd, env})}]
|
||||
: tags,
|
||||
[]
|
||||
const branchTags = await Promise.all(
|
||||
(await getTags(branch.name, {cwd, env}))
|
||||
.map(tag => {
|
||||
const [, version, channel] = tag.match(tagRegexp) || [];
|
||||
return {gitTag: tag, version, channel};
|
||||
})
|
||||
.filter(({version}) => version && semver.valid(semver.clean(version)))
|
||||
.map(async ({gitTag, ...rest}) => ({gitTag, gitHead: await getTagHead(gitTag, {cwd, env}), ...rest}))
|
||||
);
|
||||
|
||||
debug('found tags for branch %s: %o', branch.name, branchTags);
|
||||
|
||||
Reference in New Issue
Block a user