semantic-release/lib/get-last-release.js
Pierre Vanduynslager 7b4052470b feat: support multiple branches and distribution channels
- Allow to configure multiple branches to release from
- Allow to define a distribution channel associated with each branch
- Manage the availability on distribution channels based on git merges
- Support regular releases, maintenance releases and pre-releases
- Add the `addChannel` plugin step to make an existing release available on a different distribution channel

BREAKING CHANGE: the `branch` option has been removed in favor of `branches`

The new `branches` option expect either an Array or a single branch definition. To migrate your configuration:
- If you want to publish package from multiple branches, please the configuration documentation
- If you use the default configuration and want to publish only from `master`: nothing to change
- If you use the `branch` configuration and want to publish only from one branch: replace `branch` by `branches` (`"branch": "my-release-branch"` => `"branches": "my-release-branch"`)
2018-11-29 14:13:03 -05:00

40 lines
1.4 KiB
JavaScript

const {isUndefined} = require('lodash');
const semver = require('semver');
const {makeTag} = require('./utils');
/**
* Last release.
*
* @typedef {Object} LastRelease
* @property {string} version The version number of the last release.
* @property {string} [gitHead] The Git reference used to make the last release.
*/
/**
* Determine the Git tag and version of the last tagged release.
*
* - Filter out the branch tags that are not valid semantic version
* - Sort the versions
* - Retrive the highest version
*
* @param {Object} context semantic-release context.
* @param {Object} params Function parameters.
* @param {Object} params.before Find only releases with version number lower than this version.
*
* @return {LastRelease} The last tagged release or empty object if none is found.
*/
module.exports = ({branch: {name, tags, type}, options: {tagFormat}, logger}, {before} = {}) => {
const [{version, gitTag, gitHead, channel} = {}] = tags
.filter(tag => type === 'prerelease' || !semver.prerelease(tag.version))
.filter(tag => isUndefined(before) || semver.lt(tag.version, before))
.sort((a, b) => semver.rcompare(a.version, b.version));
if (gitTag) {
logger.log(`Found git tag ${gitTag} associated with version ${version} on branch ${name}`);
return {version, gitTag, gitHead, channel, name: makeTag(tagFormat, version)};
}
logger.log(`No git tag version found on branch ${name}`);
return {};
};