Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
13 changed files
with
440 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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); | ||
|
||
const versiontoAdd = uniqBy( | ||
branch.tags.filter( | ||
({channels, version}) => | ||
!channels.includes(branch.channel) && | ||
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, | ||
gitTag: makeTag(tagFormat, version, branch.channel), | ||
name, | ||
gitHead: gitTag, | ||
}, | ||
}; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.