- Add a new plugin type: `publish` - Add support for multi-plugin. A plugin module can now return an object with a property for each plugin type - Uses by default [npm](https://github.com/semantic-release/npm) and [github](https://github.com/semantic-release/github) in addition of Travis for the verify condition plugin - Uses by default [npm](https://github.com/semantic-release/npm) and [github](https://github.com/semantic-release/github) for the publish plugin - `gitTag` if one can be found is passed to `generateNotes` for both `lastRelease` and `nextRelease` - `semantic-release` now verifies the plugin configuration (in the `release` property of `package.json`) and throws an error if it's invalid - `semantic-release` now verifies each plugin output and will throw an error if a plugin returns an unexpected value. BREAKING CHANGE: `githubToken`, `githubUrl` and `githubApiPathPrefix` have to be set at the [github](https://github.com/semantic-release/github) plugin level. They can be set via `GH_TOKEN`, `GH_URL` and `GH_PREFIX` environment variables. BREAKING CHANGE: the `npm` parameter is not passed to any plugin anymore. Each plugin have to read `.npmrc` if they needs to (with https://github.com/kevva/npm-conf for example).
53 lines
2.3 KiB
JavaScript
53 lines
2.3 KiB
JavaScript
const debug = require('debug')('semantic-release:get-version-head');
|
|
const SemanticReleaseError = require('@semantic-release/error');
|
|
const {gitTagHead, gitCommitTag, isCommitInHistory, unshallow} = require('./git');
|
|
|
|
/**
|
|
* Get the commit sha for a given version, if it's contained in the given branch.
|
|
*
|
|
* @param {string} gitHead The commit sha to look for.
|
|
* @param {string} version The version corresponding to the commit sha to look for. Used to search in git tags.
|
|
*
|
|
* @return {Promise<Object>} A Promise that resolves to an object with the `gitHead` and `gitTag` for the the `version`.
|
|
*
|
|
* @throws {SemanticReleaseError} with code `ENOTINHISTORY` if `gitHead` or the commit sha dereived from `version` is not in the direct history of `branch`.
|
|
* @throws {SemanticReleaseError} with code `ENOGITHEAD` if `gitHead` is undefined and no commit sha can be found for the `version`.
|
|
*/
|
|
module.exports = async (gitHead, version) => {
|
|
// Check if gitHead is defined and exists in release branch
|
|
if (gitHead && (await isCommitInHistory(gitHead))) {
|
|
debug('Use gitHead: %s', gitHead);
|
|
return {gitHead, gitTag: await gitCommitTag(gitHead)};
|
|
}
|
|
|
|
await unshallow();
|
|
|
|
// Check if gitHead is defined and exists in release branch again
|
|
if (gitHead && (await isCommitInHistory(gitHead))) {
|
|
debug('Use gitHead: %s', gitHead);
|
|
return {gitHead, gitTag: await gitCommitTag(gitHead)};
|
|
}
|
|
|
|
let tagHead;
|
|
if (version) {
|
|
// If a version is defined search a corresponding tag
|
|
tagHead = (await gitTagHead(`v${version}`)) || (await gitTagHead(version));
|
|
|
|
// Check if tagHead is found and exists in release branch again
|
|
if (tagHead && (await isCommitInHistory(tagHead))) {
|
|
debug('Use tagHead: %s', tagHead);
|
|
return {gitHead: tagHead, gitTag: await gitCommitTag(tagHead)};
|
|
}
|
|
}
|
|
|
|
// Either gitHead is defined or a tagHead has been found but none is in the branch history
|
|
if (gitHead || tagHead) {
|
|
const error = new SemanticReleaseError('Commit not in history', 'ENOTINHISTORY');
|
|
error.gitHead = gitHead || tagHead;
|
|
throw error;
|
|
}
|
|
|
|
// There is no gitHead in the last release and there is no tags correponsing to the last release version
|
|
throw new SemanticReleaseError('There is no commit associated with last release', 'ENOGITHEAD');
|
|
};
|