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

Commit a5b922d

Browse files
committed
feat: migrate from travis_after_all to travis-after-all
`travis_after_all` is a python script that had to be added to .travis.yml manually to support testing multiple node versions. `travis-after-all` is the same thing (even better actually, as it supports "allowed-failures") and can be required. This is now part of this verification plugin. You may now happily apply this patch to your `.travis.yml`. (It keeps working if you leave in, so this isn't even breaking 😱) ```diff --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a5fbddb..c76091b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,9 +14,6 @@ before_install: - npm i -g npm@^2.0.0 before_script: - npm prune -- curl -Lo travis_after_all.py https://git.io/vLSON after_success: -- python travis_after_all.py -- export $(cat .to_export_back) - npm run semantic-release -- ```
1 parent 6ac52c6 commit a5b922d

File tree

3 files changed

+58
-23
lines changed

3 files changed

+58
-23
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414
}
1515
},
1616
"dependencies": {
17-
"@semantic-release/error": "^1.0.0"
17+
"@semantic-release/error": "^1.0.0",
18+
"travis-after-all": "^1.3.0"
1819
},
1920
"devDependencies": {
2021
"babel": "^5.5.8",
2122
"coveralls": "^2.11.2",
2223
"mkdirp": "^0.5.1",
2324
"nyc": "^3.0.0",
25+
"proxyquire": "^1.7.1",
2426
"rimraf": "^2.4.0",
2527
"semantic-release": "^5.0.1",
2628
"standard": "^5.1.0",

src/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { unlinkSync } = require('fs')
1+
const travisAfterAll = require('travis-after-all')
22

33
const SRError = require('@semantic-release/error')
44

@@ -10,14 +10,13 @@ module.exports = function (pluginConfig, {env, options}, cb) {
1010

1111
if (options.branch !== env.TRAVIS_BRANCH) return cb(new SRError(`Branch is not ${options.branch}`, 'EBRANCHMISMATCH'))
1212

13-
if (env.BUILD_MINION === 'YES') return cb(new SRError('Not publishing from minion', 'ENOBUILDLEADER'))
13+
travisAfterAll((code, err) => {
14+
if (code === 0) return cb(null)
1415

15-
if (env.BUILD_LEADER === 'YES') {
16-
if (env.BUILD_AGGREGATE_STATUS !== 'others_succeeded') return cb(new SRError('Not publishing when other jobs in the build matrix fail.', 'EOTHERSFAILED'))
16+
if (code === 1) return cb(new SRError('Not publishing when other jobs in the build matrix fail.', 'EOTHERSFAILED'))
1717

18-
try { unlinkSync('./travis_after_all.py') } catch (e) {}
19-
try { unlinkSync('./.to_export_back') } catch (e) {}
20-
}
18+
if (code === 2) return cb(new SRError('Not publishing from minion', 'ENOBUILDLEADER'))
2119

22-
cb(null)
20+
cb(err || new SRError('travis-after-all return unexpected error code', 'ETAAFAIL'))
21+
})
2322
}

test/specs/index.js

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
const proxyquire = require('proxyquire')
12
const { test } = require('tap')
23
const SRError = require('@semantic-release/error')
34

4-
const condition = require('../../dist')
5+
const condition = proxyquire('../../', {
6+
'travis-after-all': (cb) => cb(0)
7+
})
58

69
test('raise errors in travis environment', (t) => {
710
t.test('only runs on travis', (tt) => {
@@ -82,15 +85,15 @@ test('raise errors in travis environment', (t) => {
8285
})
8386
})
8487

85-
t.test('supports travis_after_all', (tt) => {
86-
tt.plan(5)
88+
t.test('supports travis-after-all', (tt) => {
89+
tt.plan(8)
8790

88-
condition({}, {
91+
proxyquire('../../', {
92+
'travis-after-all': (cb) => cb(0)
93+
})({}, {
8994
env: {
9095
TRAVIS: 'true',
91-
TRAVIS_BRANCH: 'master',
92-
BUILD_LEADER: 'YES',
93-
BUILD_AGGREGATE_STATUS: 'others_succeeded'
96+
TRAVIS_BRANCH: 'master'
9497
},
9598
options: {
9699
branch: 'master'
@@ -99,11 +102,12 @@ test('raise errors in travis environment', (t) => {
99102
tt.is(err, null)
100103
})
101104

102-
condition({}, {
105+
proxyquire('../../', {
106+
'travis-after-all': (cb) => cb(2)
107+
})({}, {
103108
env: {
104109
TRAVIS: 'true',
105-
TRAVIS_BRANCH: 'master',
106-
BUILD_MINION: 'YES'
110+
TRAVIS_BRANCH: 'master'
107111
},
108112
options: {
109113
branch: 'master'
@@ -113,12 +117,12 @@ test('raise errors in travis environment', (t) => {
113117
tt.is(err.code, 'ENOBUILDLEADER')
114118
})
115119

116-
condition({}, {
120+
proxyquire('../../', {
121+
'travis-after-all': (cb) => cb(1)
122+
})({}, {
117123
env: {
118124
TRAVIS: 'true',
119-
TRAVIS_BRANCH: 'master',
120-
BUILD_LEADER: 'YES',
121-
BUILD_AGGREGATE_STATUS: 'others_failed'
125+
TRAVIS_BRANCH: 'master'
122126
},
123127
options: {
124128
branch: 'master'
@@ -127,5 +131,35 @@ test('raise errors in travis environment', (t) => {
127131
tt.ok(err instanceof SRError)
128132
tt.is(err.code, 'EOTHERSFAILED')
129133
})
134+
135+
proxyquire('../../', {
136+
'travis-after-all': (cb) => cb('weird?')
137+
})({}, {
138+
env: {
139+
TRAVIS: 'true',
140+
TRAVIS_BRANCH: 'master'
141+
},
142+
options: {
143+
branch: 'master'
144+
}
145+
}, (err) => {
146+
tt.ok(err instanceof SRError)
147+
tt.is(err.code, 'ETAAFAIL')
148+
})
149+
150+
var error = {}
151+
proxyquire('../../', {
152+
'travis-after-all': (cb) => cb(null, error)
153+
})({}, {
154+
env: {
155+
TRAVIS: 'true',
156+
TRAVIS_BRANCH: 'master'
157+
},
158+
options: {
159+
branch: 'master'
160+
}
161+
}, (err) => {
162+
tt.is(err, error)
163+
})
130164
})
131165
})

0 commit comments

Comments
 (0)