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.
This commit is contained in:
		
							parent
							
								
									7b8f632396
								
							
						
					
					
						commit
						700ec9d4ca
					
				| @ -36,6 +36,7 @@ | |||||||
|     "parse-github-repo-url": "^1.0.0", |     "parse-github-repo-url": "^1.0.0", | ||||||
|     "require-relative": "^0.8.7", |     "require-relative": "^0.8.7", | ||||||
|     "run-auto": "^1.1.2", |     "run-auto": "^1.1.2", | ||||||
|  |     "run-series": "^1.1.2", | ||||||
|     "semver": "^5.0.1" |     "semver": "^5.0.1" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|  | |||||||
| @ -1,13 +1,34 @@ | |||||||
| const relative = require('require-relative') | const relative = require('require-relative') | ||||||
|  | const series = require('run-series') | ||||||
| 
 | 
 | ||||||
| let exports = module.exports = function (options) { | let exports = module.exports = function (options) { | ||||||
|   return { |   var plugins = { | ||||||
|     analyzeCommits: exports.normalize(options.analyzeCommits, '@semantic-release/commit-analyzer'), |     analyzeCommits: exports.normalize(options.analyzeCommits, '@semantic-release/commit-analyzer'), | ||||||
|     generateNotes: exports.normalize(options.generateNotes, '@semantic-release/release-notes-generator'), |     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') |     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) { | exports.normalize = function (pluginConfig, fallback) { | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								test/mocks/plugin-error-a.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/mocks/plugin-error-a.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | module.exports = function (config, options, cb) { | ||||||
|  |   cb(new Error('a')) | ||||||
|  | } | ||||||
							
								
								
									
										3
									
								
								test/mocks/plugin-error-b.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/mocks/plugin-error-b.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | module.exports = function (config, options, cb) { | ||||||
|  |   cb(new Error('b')) | ||||||
|  | } | ||||||
							
								
								
									
										3
									
								
								test/mocks/plugin-result-a.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/mocks/plugin-result-a.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | module.exports = function (config, options, cb) { | ||||||
|  |   cb(null, 'a') | ||||||
|  | } | ||||||
							
								
								
									
										3
									
								
								test/mocks/plugin-result-b.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/mocks/plugin-result-b.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | module.exports = function (config, options, cb) { | ||||||
|  |   cb(null, 'b') | ||||||
|  | } | ||||||
| @ -3,7 +3,7 @@ const test = require('tap').test | |||||||
| const plugins = require('../../dist/lib/plugins') | const plugins = require('../../dist/lib/plugins') | ||||||
| 
 | 
 | ||||||
| test('export plugins', (t) => { | test('export plugins', (t) => { | ||||||
|   t.plan(4) |   t.plan(5) | ||||||
| 
 | 
 | ||||||
|   const defaultPlugins = plugins({}) |   const defaultPlugins = plugins({}) | ||||||
| 
 | 
 | ||||||
| @ -11,6 +11,59 @@ test('export plugins', (t) => { | |||||||
|   t.is(typeof defaultPlugins.generateNotes, 'function') |   t.is(typeof defaultPlugins.generateNotes, 'function') | ||||||
|   t.is(typeof defaultPlugins.verifyConditions, 'function') |   t.is(typeof defaultPlugins.verifyConditions, 'function') | ||||||
|   t.is(typeof defaultPlugins.verifyRelease, '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) => { | test('normalize and load plugin', (t) => { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user