|
1 | 1 | const travisAfterAll = require('travis-after-all')
|
2 | 2 |
|
| 3 | +const semver = require('semver') |
3 | 4 | const SRError = require('@semantic-release/error')
|
4 | 5 |
|
5 | 6 | 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 | + } |
12 | 40 |
|
13 | 41 | travisAfterAll((code, err) => {
|
14 | 42 | if (code === 0) return cb(null)
|
15 | 43 |
|
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')) |
21 | 59 | })
|
22 | 60 | }
|
0 commit comments