feat: Extract npm and github publish to plugins

- 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).
This commit is contained in:
Pierre Vanduynslager
2017-11-21 16:41:04 -05:00
parent 991a7b5f97
commit d548edcf37
42 changed files with 1111 additions and 1122 deletions
+6 -8
View File
@@ -1,10 +1,8 @@
const execa = require('execa');
const gitLogParser = require('git-log-parser');
const getStream = require('get-stream');
const debug = require('debug')('semantic-release:get-commits');
const {unshallow} = require('./git');
const getVersionHead = require('./get-version-head');
const {debugShell} = require('./debug');
const logger = require('./logger');
/**
* Commit message.
@@ -47,10 +45,11 @@ const logger = require('./logger');
* @throws {SemanticReleaseError} with code `ENOTINHISTORY` if `lastRelease.gitHead` or the commit sha derived from `config.lastRelease.version` is not in the direct history of `branch`.
* @throws {SemanticReleaseError} with code `ENOGITHEAD` if `lastRelease.gitHead` is undefined and no commit sha can be found for the `config.lastRelease.version`.
*/
module.exports = async ({version, gitHead}, branch) => {
module.exports = async ({version, gitHead}, branch, logger) => {
let gitTag;
if (gitHead || version) {
try {
gitHead = await getVersionHead(gitHead, version, branch);
({gitHead, gitTag} = await getVersionHead(gitHead, version, branch));
} catch (err) {
if (err.code === 'ENOTINHISTORY') {
logger.error(notInHistoryMessage(err.gitHead, branch, version));
@@ -63,8 +62,7 @@ module.exports = async ({version, gitHead}, branch) => {
} else {
logger.log('No previous release found, retrieving all commits');
// If there is no gitHead nor a version, there is no previous release. Unshallow the repo in order to retrieve all commits
const shell = await execa('git', ['fetch', '--unshallow', '--tags'], {reject: false});
debugShell('Unshallow repo', shell, debug);
await unshallow();
}
Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}});
@@ -77,7 +75,7 @@ module.exports = async ({version, gitHead}, branch) => {
);
logger.log('Found %s commits since last release', commits.length);
debug('Parsed commits: %o', commits);
return {commits, lastRelease: {version, gitHead}};
return {commits, lastRelease: {version, gitHead, gitTag}};
};
function noGitHeadMessage(branch, version) {