Skip to content
This repository was archived by the owner on Jan 14, 2018. It is now read-only.

Commit 16dffd6

Browse files
committed
fix: make error messages meaningful
1 parent 2f60395 commit 16dffd6

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
},
1616
"dependencies": {
1717
"@semantic-release/error": "^1.0.0",
18-
"travis-after-all": "^1.3.0"
18+
"travis-after-all": "^1.3.0",
19+
"semver": "^5.0.3"
1920
},
2021
"devDependencies": {
2122
"babel": "^5.5.8",

src/index.js

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,60 @@
11
const travisAfterAll = require('travis-after-all')
22

3+
const semver = require('semver')
34
const SRError = require('@semantic-release/error')
45

56
module.exports = function (pluginConfig, {env, options}, cb) {
6-
if (env.TRAVIS !== 'true') return cb(new SRError('Not running on Travis', 'ENOTRAVIS'))
7-
8-
if (env.hasOwnProperty('TRAVIS_PULL_REQUEST') && env.TRAVIS_PULL_REQUEST !== 'false') return cb(new SRError('Not publishing from pull requests', 'EPULLREQUEST'))
9-
if (env.TRAVIS_TAG) return cb(new SRError('Not publishing from tags', 'EGITTAG'))
10-
11-
if (options.branch !== env.TRAVIS_BRANCH) return cb(new SRError(`Branch is not ${options.branch}`, 'EBRANCHMISMATCH'))
7+
if (env.TRAVIS !== 'true') {
8+
return cb(new SRError(
9+
'semantic-release didn’t run on Travis CI and therefore a new version won’t be published.\n' +
10+
'You can customize this behavior using "verifyConditions" plugins: git.io/sr-plugins',
11+
'ENOTRAVIS'
12+
))
13+
}
14+
15+
if (env.hasOwnProperty('TRAVIS_PULL_REQUEST') && env.TRAVIS_PULL_REQUEST !== 'false') {
16+
return cb(new SRError(
17+
'This test run was triggered by a pull request and therefore a new version won’t be published.',
18+
'EPULLREQUEST'
19+
))
20+
}
21+
22+
if (env.TRAVIS_TAG) {
23+
let errorMessage = 'This test run was triggered by a git tag and therefore a new version won’t be published.'
24+
25+
if (semver.valid(env.TRAVIS_TAG)) {
26+
errorMessage += '\nIt is very likely that this tag was created by semantic-release itself.\n' +
27+
'Everything is okay. For log output of the actual publishing process look at the build that ran before this one.'
28+
}
29+
30+
return cb(new SRError(errorMessage, 'EGITTAG'))
31+
}
32+
33+
if (options.branch !== env.TRAVIS_BRANCH) {
34+
return cb(new SRError(
35+
`This test run was triggered on the branch ${env.TRAVIS_BRANCH}, while semantic-release is configured to only publish from ${options.branch}.\n` +
36+
'You can customize this behavior using the "branch" option: git.io/sr-options',
37+
'EBRANCHMISMATCH'
38+
))
39+
}
1240

1341
travisAfterAll((code, err) => {
1442
if (code === 0) return cb(null)
1543

16-
if (code === 1) return cb(new SRError('Not publishing when other jobs in the build matrix fail.', 'EOTHERSFAILED'))
17-
18-
if (code === 2) return cb(new SRError('Not publishing from minion', 'ENOBUILDLEADER'))
19-
20-
cb(err || new SRError('travis-after-all return unexpected error code', 'ETAAFAIL'))
44+
if (code === 1) {
45+
return cb(new SRError(
46+
'In this test run not all jobs passed and therefore a new version won’t be published.',
47+
'EOTHERSFAILED'
48+
))
49+
}
50+
51+
if (code === 2) {
52+
return cb(new SRError(
53+
'This test run is not the build leader and therefore a new version won’t be published.',
54+
'ENOBUILDLEADER'
55+
))
56+
}
57+
58+
cb(err || new SRError('travis-after-all returned unexpected error code', 'ETAAFAIL'))
2159
})
2260
}

0 commit comments

Comments
 (0)