Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2d6db2ce5 | ||
|
|
700ec9d4ca | ||
|
|
7b8f632396 |
@@ -147,10 +147,14 @@ This plugin is responsible for generating release notes. Call the callback with
|
||||
|
||||
This plugins is responsible for verifying that a release should happen in the first place. For example, the [default implementation](https://github.com/semantic-release/condition-travis/) verifies that the publish is happening on Travis, that it's the right branch, and that all other build jobs succeeded. There are more use cases for this, e.g. verifying that test coverage is above a certain threshold or that there are no [vulnerabilities](https://nodesecurity.io/) in your dependencies. Be creative.
|
||||
|
||||
Passing an array of plugins will run them in series.
|
||||
|
||||
### `verifyRelease`
|
||||
|
||||
This plugin is responsible for verifying a release that was determined before and is about to be published. There is no default implementation. It additionally receives `nextRelease`, `lastRelease` and `commits` inside `config`. While `commits` is the same as with analyzeCommits, `nextRelease` contains a `type` (e.g. `'major'`) and the new version (e.g. `'1.0.0'`) and `lastRelease` contains the old `version`, the `gitHead` at the time of the release and the npm dist-`tag` (e.g. `'latest'`). Using this information you could [detect breaking changes](https://github.com/semantic-release/cracks) or hold back certain types of releases. Again: Be creative.
|
||||
|
||||
Passing an array of plugins will run them in series.
|
||||
|
||||
### `getLastRelease`
|
||||
|
||||
This plugin is responsible for determining a package's last release version. The [default implementation](https://github.com/semantic-release/last-release-npm) uses the last published version on a npm registry.
|
||||
|
||||
@@ -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": {
|
||||
|
||||
+20
-20
@@ -6,7 +6,7 @@ const log = require('npmlog')
|
||||
const nopt = require('nopt')
|
||||
const npmconf = require('npmconf')
|
||||
|
||||
const PREFIX = 'semantic-release'
|
||||
log.heading = 'semantic-release'
|
||||
const env = process.env
|
||||
const pkg = JSON.parse(readFileSync('./package.json'))
|
||||
const knownOptions = {
|
||||
@@ -33,7 +33,7 @@ const plugins = require('./lib/plugins')(options)
|
||||
|
||||
npmconf.load({}, (err, conf) => {
|
||||
if (err) {
|
||||
log.error(PREFIX, 'Failed to load npm config.', err)
|
||||
log.error('init', 'Failed to load npm config.', err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -50,25 +50,25 @@ npmconf.load({}, (err, conf) => {
|
||||
|
||||
log.level = npm.loglevel
|
||||
|
||||
const config = {PREFIX, log, env, pkg, options, plugins, npm}
|
||||
const config = {env, pkg, options, plugins, npm}
|
||||
|
||||
let hide = {}
|
||||
if (options.githubToken) hide.githubToken = '***'
|
||||
|
||||
log.verbose(PREFIX, 'options:', _.assign({}, options, hide))
|
||||
log.verbose(PREFIX, 'Verifying config.')
|
||||
log.verbose('init', 'options:', _.assign({}, options, hide))
|
||||
log.verbose('init', 'Verifying config.')
|
||||
|
||||
const errors = require('./lib/verify')(config)
|
||||
errors.forEach((err) => log.error(PREFIX, `${err.message} ${err.code}`))
|
||||
errors.forEach((err) => log.error('init', `${err.message} ${err.code}`))
|
||||
if (errors.length) process.exit(1)
|
||||
|
||||
if (options.argv.remain[0] === 'pre') {
|
||||
log.verbose(PREFIX, 'Running pre-script.')
|
||||
log.verbose(PREFIX, 'Veriying conditions.')
|
||||
log.verbose('pre', 'Running pre-script.')
|
||||
log.verbose('pre', 'Veriying conditions.')
|
||||
|
||||
plugins.verifyConditions(config, (err) => {
|
||||
if (err) {
|
||||
log[options.debug ? 'warn' : 'error'](PREFIX, err.message)
|
||||
log[options.debug ? 'warn' : 'error']('pre', err.message)
|
||||
if (!options.debug) process.exit(1)
|
||||
}
|
||||
|
||||
@@ -87,15 +87,15 @@ npmconf.load({}, (err, conf) => {
|
||||
}
|
||||
|
||||
conf.save('project', (err) => {
|
||||
if (err) return log.error(PREFIX, 'Failed to save npm config.', err)
|
||||
if (err) return log.error('pre', 'Failed to save npm config.', err)
|
||||
|
||||
if (wroteNpmRc) log.verbose(PREFIX, 'Wrote authToken to .npmrc.')
|
||||
if (wroteNpmRc) log.verbose('pre', 'Wrote authToken to .npmrc.')
|
||||
|
||||
require('./pre')(config, (err, release) => {
|
||||
if (err) {
|
||||
log.error(PREFIX, 'Failed to determine new version.')
|
||||
log.error('pre', 'Failed to determine new version.')
|
||||
|
||||
const args = [PREFIX, (err.code ? `${err.code} ` : '') + err.message]
|
||||
const args = ['pre', (err.code ? `${err.code} ` : '') + err.message]
|
||||
if (err.stack) args.push(err.stack)
|
||||
log.error(...args)
|
||||
process.exit(1)
|
||||
@@ -103,10 +103,10 @@ npmconf.load({}, (err, conf) => {
|
||||
|
||||
const message = `Determined version ${release.version} as "${npm.tag}".`
|
||||
|
||||
log.verbose(PREFIX, message)
|
||||
log.verbose('pre', message)
|
||||
|
||||
if (options.debug) {
|
||||
log.error(PREFIX, `${message} Not publishing in debug mode.`, release)
|
||||
log.error('pre', `${message} Not publishing in debug mode.`, release)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -114,22 +114,22 @@ npmconf.load({}, (err, conf) => {
|
||||
version: release.version
|
||||
}), null, 2))
|
||||
|
||||
log.verbose(PREFIX, `Wrote version ${release.version} to package.json.`)
|
||||
log.verbose('pre', `Wrote version ${release.version} to package.json.`)
|
||||
})
|
||||
})
|
||||
})
|
||||
} else if (options.argv.remain[0] === 'post') {
|
||||
log.verbose(PREFIX, 'Running post-script.')
|
||||
log.verbose('post', 'Running post-script.')
|
||||
|
||||
require('./post')(config, (err, published, release) => {
|
||||
if (err) {
|
||||
log.error(PREFIX, 'Failed to publish release notes.', err)
|
||||
log.error('post', 'Failed to publish release notes.', err)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
log.verbose(PREFIX, `${published ? 'Published' : 'Generated'} release notes.`, release)
|
||||
log.verbose('post', `${published ? 'Published' : 'Generated'} release notes.`, release)
|
||||
})
|
||||
} else {
|
||||
log.error(PREFIX, `Command "${options.argv.remain[0]}" not recognized. User either "pre" or "post"`)
|
||||
log.error('post', `Command "${options.argv.remain[0]}" not recognized. User either "pre" or "post"`)
|
||||
}
|
||||
})
|
||||
|
||||
+24
-3
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(new Error('a'))
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(new Error('b'))
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(null, 'a')
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (config, options, cb) {
|
||||
cb(null, 'b')
|
||||
}
|
||||
+54
-1
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user