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

Commit 5f24a60

Browse files
committed
feat: initial implementation
1 parent e9e518a commit 5f24a60

File tree

3 files changed

+20
-160
lines changed

3 files changed

+20
-160
lines changed

index.js

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,33 @@
1-
var travisAfterAll = require('travis-after-all')
2-
3-
var semver = require('semver')
41
var SRError = require('@semantic-release/error')
52

63
module.exports = function (pluginConfig, config, cb) {
74
var env = config.env
85
var options = config.options
96

10-
if (env.TRAVIS !== 'true') {
7+
if (env.CI_NAME !== 'codeship') {
118
return cb(new SRError(
12-
'semantic-release didn’t run on Travis CI and therefore a new version won’t be published.\n' +
9+
'semantic-release didn’t run on Codeship and therefore a new version won’t be published.\n' +
1310
'You can customize this behavior using "verifyConditions" plugins: git.io/sr-plugins',
14-
'ENOTRAVIS'
11+
'ENOCODESHIP'
1512
))
1613
}
1714

18-
if (env.hasOwnProperty('TRAVIS_PULL_REQUEST') && env.TRAVIS_PULL_REQUEST !== 'false') {
15+
if (env.hasOwnProperty('CI_PULL_REQUEST') && env.CI_PULL_REQUEST !== 'false') {
1916
return cb(new SRError(
2017
'This test run was triggered by a pull request and therefore a new version won’t be published.',
2118
'EPULLREQUEST'
2219
))
2320
}
2421

25-
if (env.TRAVIS_TAG) {
26-
var errorMessage = 'This test run was triggered by a git tag and therefore a new version won’t be published.'
27-
28-
if (semver.valid(env.TRAVIS_TAG)) {
29-
errorMessage += '\nIt is very likely that this tag was created by semantic-release itself.\n' +
30-
'Everything is okay. For log output of the actual publishing process look at the build that ran before this one.'
31-
}
32-
33-
return cb(new SRError(errorMessage, 'EGITTAG'))
34-
}
35-
36-
if (options.branch !== env.TRAVIS_BRANCH) {
22+
if (options.branch !== env.CI_BRANCH) {
3723
return cb(new SRError(
38-
'This test run was triggered on the branch ' + env.TRAVIS_BRANCH +
24+
'This test run was triggered on the branch ' + env.CI_BRANCH +
3925
', while semantic-release is configured to only publish from ' +
4026
options.branch + '.\n' +
4127
'You can customize this behavior using the "branch" option: git.io/sr-options',
4228
'EBRANCHMISMATCH'
4329
))
4430
}
4531

46-
travisAfterAll(function (code, err) {
47-
if (code === 0) return cb(null)
48-
49-
if (code === 1) {
50-
return cb(new SRError(
51-
'In this test run not all jobs passed and therefore a new version won’t be published.',
52-
'EOTHERSFAILED'
53-
))
54-
}
55-
56-
if (code === 2) {
57-
return cb(new SRError(
58-
'This test run is not the build leader and therefore a new version won’t be published.',
59-
'ENOBUILDLEADER'
60-
))
61-
}
62-
63-
cb(err || new SRError('travis-after-all returned unexpected error code', 'ETAAFAIL'))
64-
})
32+
cb(null)
6533
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"devDependencies": {
1212
"coveralls": "^2.11.2",
1313
"nyc": "^5.0.0",
14-
"proxyquire": "^1.7.1",
15-
"semantic-release": "^4.3.5",
14+
"semantic-release": "^6.0.3",
1615
"standard": "^5.1.0",
1716
"tap": "^5.0.0"
1817
},

test.js

Lines changed: 12 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,38 @@
1-
var proxyquire = require('proxyquire')
21
var test = require('tap').test
32
var SRError = require('@semantic-release/error')
43

5-
var condition = proxyquire('./', {
6-
'travis-after-all': function (cb) {
7-
cb(0)
8-
}
9-
})
4+
var condition = require('./')
105

11-
test('raise errors in travis environment', function (t) {
12-
t.test('only runs on travis', function (tt) {
6+
test('raise errors in codeship environment', function (t) {
7+
t.test('only runs on codeship', function (tt) {
138
tt.plan(2)
149

1510
condition({}, {env: {}}, function (err) {
1611
tt.ok(err instanceof SRError)
17-
tt.is(err.code, 'ENOTRAVIS')
12+
tt.is(err.code, 'ENOCODESHIP')
1813
})
1914
})
2015

2116
t.test('not running on pull requests', function (tt) {
2217
tt.plan(2)
2318
condition({}, {
2419
env: {
25-
TRAVIS: 'true',
26-
TRAVIS_PULL_REQUEST: '105'
20+
CI_NAME: 'codeship',
21+
CI_PULL_REQUEST: 'true'
2722
}
2823
}, function (err) {
2924
tt.ok(err instanceof SRError)
3025
tt.is(err.code, 'EPULLREQUEST')
3126
})
3227
})
3328

34-
t.test('not running on tags', function (tt) {
35-
tt.plan(2)
36-
condition({}, {
37-
env: {
38-
TRAVIS: 'true',
39-
TRAVIS_PULL_REQUEST: 'false',
40-
TRAVIS_TAG: 'v1.0.0'
41-
}
42-
}, function (err) {
43-
tt.ok(err instanceof SRError)
44-
tt.is(err.code, 'EGITTAG')
45-
})
46-
})
47-
4829
t.test('only running on specified branch', function (tt) {
4930
tt.plan(5)
5031

5132
condition({}, {
5233
env: {
53-
TRAVIS: 'true',
54-
TRAVIS_BRANCH: 'master'
34+
CI_NAME: 'codeship',
35+
CI_BRANCH: 'master'
5536
},
5637
options: {
5738
branch: 'master'
@@ -62,8 +43,8 @@ test('raise errors in travis environment', function (t) {
6243

6344
condition({}, {
6445
env: {
65-
TRAVIS: 'true',
66-
TRAVIS_BRANCH: 'notmaster'
46+
CI_NAME: 'codeship',
47+
CI_BRANCH: 'notmaster'
6748
},
6849
options: {
6950
branch: 'master'
@@ -75,8 +56,8 @@ test('raise errors in travis environment', function (t) {
7556

7657
condition({}, {
7758
env: {
78-
TRAVIS: 'true',
79-
TRAVIS_BRANCH: 'master'
59+
CI_NAME: 'codeship',
60+
CI_BRANCH: 'master'
8061
},
8162
options: {
8263
branch: 'foo'
@@ -87,93 +68,5 @@ test('raise errors in travis environment', function (t) {
8768
})
8869
})
8970

90-
t.test('supports travis-after-all', function (tt) {
91-
tt.plan(8)
92-
93-
proxyquire('./', {
94-
'travis-after-all': function (cb) {
95-
cb(0)
96-
}
97-
})({}, {
98-
env: {
99-
TRAVIS: 'true',
100-
TRAVIS_BRANCH: 'master'
101-
},
102-
options: {
103-
branch: 'master'
104-
}
105-
}, function (err) {
106-
tt.is(err, null)
107-
})
108-
109-
proxyquire('./', {
110-
'travis-after-all': function (cb) {
111-
cb(2)
112-
}
113-
})({}, {
114-
env: {
115-
TRAVIS: 'true',
116-
TRAVIS_BRANCH: 'master'
117-
},
118-
options: {
119-
branch: 'master'
120-
}
121-
}, function (err) {
122-
tt.ok(err instanceof SRError)
123-
tt.is(err.code, 'ENOBUILDLEADER')
124-
})
125-
126-
proxyquire('./', {
127-
'travis-after-all': function (cb) {
128-
cb(1)
129-
}
130-
})({}, {
131-
env: {
132-
TRAVIS: 'true',
133-
TRAVIS_BRANCH: 'master'
134-
},
135-
options: {
136-
branch: 'master'
137-
}
138-
}, function (err) {
139-
tt.ok(err instanceof SRError)
140-
tt.is(err.code, 'EOTHERSFAILED')
141-
})
142-
143-
proxyquire('./', {
144-
'travis-after-all': function (cb) {
145-
cb('weird?')
146-
}
147-
})({}, {
148-
env: {
149-
TRAVIS: 'true',
150-
TRAVIS_BRANCH: 'master'
151-
},
152-
options: {
153-
branch: 'master'
154-
}
155-
}, function (err) {
156-
tt.ok(err instanceof SRError)
157-
tt.is(err.code, 'ETAAFAIL')
158-
})
159-
160-
var error = {}
161-
proxyquire('./', {
162-
'travis-after-all': function (cb) {
163-
cb(null, error)
164-
}
165-
})({}, {
166-
env: {
167-
TRAVIS: 'true',
168-
TRAVIS_BRANCH: 'master'
169-
},
170-
options: {
171-
branch: 'master'
172-
}
173-
}, function (err) {
174-
tt.is(err, error)
175-
})
176-
})
177-
17871
t.end()
17972
})

0 commit comments

Comments
 (0)