From 700ec9d4ca06d7a0c4b7bc153ff284eb71e75f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6nnemann?= Date: Sat, 22 Aug 2015 14:51:57 +0200 Subject: [PATCH] feat(plugins): run verifications in series With this new feature you can pass an array of plugin locations/names to both "verifyConditions" and "verifyRelease" in your `package.json`'s "release" field. This will run multiple verification plugins in series. --- package.json | 1 + src/lib/plugins.js | 27 +++++++++++++++-- test/mocks/plugin-error-a.js | 3 ++ test/mocks/plugin-error-b.js | 3 ++ test/mocks/plugin-result-a.js | 3 ++ test/mocks/plugin-result-b.js | 3 ++ test/specs/plugins.js | 55 ++++++++++++++++++++++++++++++++++- 7 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 test/mocks/plugin-error-a.js create mode 100644 test/mocks/plugin-error-b.js create mode 100644 test/mocks/plugin-result-a.js create mode 100644 test/mocks/plugin-result-b.js diff --git a/package.json b/package.json index 2d2bb699..335479e9 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "parse-github-repo-url": "^1.0.0", "require-relative": "^0.8.7", "run-auto": "^1.1.2", + "run-series": "^1.1.2", "semver": "^5.0.1" }, "devDependencies": { diff --git a/src/lib/plugins.js b/src/lib/plugins.js index 8ed23ece..f5a0da4d 100644 --- a/src/lib/plugins.js +++ b/src/lib/plugins.js @@ -1,13 +1,34 @@ const relative = require('require-relative') +const series = require('run-series') let exports = module.exports = function (options) { - return { + var plugins = { analyzeCommits: exports.normalize(options.analyzeCommits, '@semantic-release/commit-analyzer'), generateNotes: exports.normalize(options.generateNotes, '@semantic-release/release-notes-generator'), - verifyConditions: exports.normalize(options.verifyConditions, '@semantic-release/condition-travis'), - verifyRelease: exports.normalize(options.verifyRelease, './plugin-noop'), getLastRelease: exports.normalize(options.getLastRelease, '@semantic-release/last-release-npm') } + + ;['verifyConditions', 'verifyRelease'].forEach((plugin) => { + if (!Array.isArray(options[plugin])) { + plugins[plugin] = exports.normalize( + options[plugin], + plugin === 'verifyConditions' ? + '@semantic-release/condition-travis' : + './plugin-noop' + ) + return + } + + plugins[plugin] = function (pluginOptions, cb) { + var tasks = options[plugin].map((step) => { + return exports.normalize(step, './plugin-noop').bind(null, pluginOptions) + }) + + series(tasks, cb) + } + }) + + return plugins } exports.normalize = function (pluginConfig, fallback) { diff --git a/test/mocks/plugin-error-a.js b/test/mocks/plugin-error-a.js new file mode 100644 index 00000000..f5567f4e --- /dev/null +++ b/test/mocks/plugin-error-a.js @@ -0,0 +1,3 @@ +module.exports = function (config, options, cb) { + cb(new Error('a')) +} diff --git a/test/mocks/plugin-error-b.js b/test/mocks/plugin-error-b.js new file mode 100644 index 00000000..7c8f83f8 --- /dev/null +++ b/test/mocks/plugin-error-b.js @@ -0,0 +1,3 @@ +module.exports = function (config, options, cb) { + cb(new Error('b')) +} diff --git a/test/mocks/plugin-result-a.js b/test/mocks/plugin-result-a.js new file mode 100644 index 00000000..e0717068 --- /dev/null +++ b/test/mocks/plugin-result-a.js @@ -0,0 +1,3 @@ +module.exports = function (config, options, cb) { + cb(null, 'a') +} diff --git a/test/mocks/plugin-result-b.js b/test/mocks/plugin-result-b.js new file mode 100644 index 00000000..b6cffb5e --- /dev/null +++ b/test/mocks/plugin-result-b.js @@ -0,0 +1,3 @@ +module.exports = function (config, options, cb) { + cb(null, 'b') +} diff --git a/test/specs/plugins.js b/test/specs/plugins.js index 428e8a0e..a38548cf 100644 --- a/test/specs/plugins.js +++ b/test/specs/plugins.js @@ -3,7 +3,7 @@ const test = require('tap').test const plugins = require('../../dist/lib/plugins') test('export plugins', (t) => { - t.plan(4) + t.plan(5) const defaultPlugins = plugins({}) @@ -11,6 +11,59 @@ test('export plugins', (t) => { t.is(typeof defaultPlugins.generateNotes, 'function') t.is(typeof defaultPlugins.verifyConditions, 'function') t.is(typeof defaultPlugins.verifyRelease, 'function') + t.is(typeof defaultPlugins.getLastRelease, 'function') +}) + +test('plugin pipelines', (t) => { + t.plan(3) + + t.test('get all results', (tt) => { + const pipelinePlugins = plugins({ + verifyRelease: [ + './dist/lib/plugin-noop', + './.test/mocks/plugin-result-a', + './.test/mocks/plugin-result-b' + ] + }) + + pipelinePlugins.verifyRelease({}, (err, results) => { + tt.error(err) + tt.same(results, [undefined, 'a', 'b']) + tt.end() + }) + }) + + t.test('get first error', (tt) => { + const pipelinePlugins = plugins({ + verifyConditions: [ + './dist/lib/plugin-noop', + './.test/mocks/plugin-error-a', + './.test/mocks/plugin-error-b' + ] + }) + + pipelinePlugins.verifyConditions({}, (err) => { + tt.is(err.message, 'a') + tt.end() + }) + }) + + t.test('get error and only results before', (tt) => { + const pipelinePlugins = plugins({ + verifyRelease: [ + './dist/lib/plugin-noop', + './.test/mocks/plugin-result-a', + './.test/mocks/plugin-error-b', + './.test/mocks/plugin-result-b' + ] + }) + + pipelinePlugins.verifyRelease({}, (err, results) => { + tt.is(err.message, 'b') + tt.same(results, [undefined, 'a', undefined]) + tt.end() + }) + }) }) test('normalize and load plugin', (t) => {