BREAKING CHANGE: this feature change the way semantic-release keep track of the channels on which a version has been released. It now use a JSON object stored in a [Git note](https://git-scm.com/docs/git-notes) instead of Git tags formatted as v{version}@{channel}. The tags formatted as v{version}@{channel} will now be ignored. If you have made releases with v16.0.0 on branches other than the default one you will have to update your repository. The changes to make consist in: - Finding all the versions that have been released on a branch other than the default one by searching for all tags formatted v{version}@{channel} - For each of those version: - Create a tag without the {@channel} if none doesn't already exists - Add a Git note to the tag without the {@channel} containing the channels on which the version was released formatted as `{"channels":["channel1","channel2"]}` and using `null` for the default channel (for example.`{"channels":[null,"channel1","channel2"]}`) - Push the tags and notes - Update the GitHub releases that refer to a tag formatted as v{version}@{channel} to use the tag without it - Delete the tags formatted as v{version}@{channel}
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
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 || null);
|
|
|
|
const versiontoAdd = uniqBy(
|
|
branch.tags.filter(
|
|
({channels, version}) =>
|
|
!channels.includes(branch.channel || null) &&
|
|
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 || null,
|
|
gitTag: makeTag(tagFormat, version),
|
|
name,
|
|
gitHead: gitTag,
|
|
},
|
|
};
|
|
}
|
|
};
|