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

Commit afe528d

Browse files
committed
feat: new function signature
BREAKING CHANGE: old one doesn't work anymore
1 parent 8cb7207 commit afe528d

File tree

2 files changed

+64
-36
lines changed

2 files changed

+64
-36
lines changed

src/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ const { unlinkSync } = require('fs')
22

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

5-
module.exports = function (options, pkg, argv, env, cb) {
5+
module.exports = function (pluginConfig, {env, options}, cb) {
66
if (env.TRAVIS !== 'true') return cb(new SRError('Not running on Travis', 'ENOTRAVIS'))
77

88
if (env.hasOwnProperty('TRAVIS_PULL_REQUEST') && env.TRAVIS_PULL_REQUEST !== 'false') return cb(new SRError('Not publishing from pull requests', 'EPULLREQUEST'))
99
if (env.TRAVIS_TAG) return cb(new SRError('Not publishing from tags', 'EGITTAG'))
1010

11-
const branch = (pkg.release || {}).branch || 'master'
12-
13-
if (branch !== env.TRAVIS_BRANCH) return cb(new SRError(`Branch is not ${branch}`, 'EBRANCHMISMATCH'))
11+
if (options.branch !== env.TRAVIS_BRANCH) return cb(new SRError(`Branch is not ${options.branch}`, 'EBRANCHMISMATCH'))
1412

1513
if (env.BUILD_MINION === 'YES') return cb(new SRError('Not publishing from minion', 'ENOBUILDLEADER'))
1614

test/specs/index.js

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ test('raise errors in travis environment', (t) => {
77
t.test('only runs on travis', (tt) => {
88
tt.plan(2)
99

10-
condition({}, {}, {}, {}, (err) => {
10+
condition({}, {env: {}}, (err) => {
1111
tt.ok(err instanceof SRError)
1212
tt.is(err.code, 'ENOTRAVIS')
1313
})
1414
})
1515

1616
t.test('not running on pull requests', (tt) => {
1717
tt.plan(2)
18-
condition({}, {}, {}, {
19-
TRAVIS: 'true',
20-
TRAVIS_PULL_REQUEST: '105'
18+
condition({}, {
19+
env: {
20+
TRAVIS: 'true',
21+
TRAVIS_PULL_REQUEST: '105'
22+
}
2123
}, (err) => {
2224
tt.ok(err instanceof SRError)
2325
tt.is(err.code, 'EPULLREQUEST')
@@ -26,10 +28,12 @@ test('raise errors in travis environment', (t) => {
2628

2729
t.test('not running on tags', (tt) => {
2830
tt.plan(2)
29-
condition({}, {}, {}, {
30-
TRAVIS: 'true',
31-
TRAVIS_PULL_REQUEST: 'false',
32-
TRAVIS_TAG: 'v1.0.0'
31+
condition({}, {
32+
env: {
33+
TRAVIS: 'true',
34+
TRAVIS_PULL_REQUEST: 'false',
35+
TRAVIS_TAG: 'v1.0.0'
36+
}
3337
}, (err) => {
3438
tt.ok(err instanceof SRError)
3539
tt.is(err.code, 'EGITTAG')
@@ -39,28 +43,39 @@ test('raise errors in travis environment', (t) => {
3943
t.test('only running on specified branch', (tt) => {
4044
tt.plan(5)
4145

42-
condition({}, {}, {}, {
43-
TRAVIS: 'true',
44-
TRAVIS_BRANCH: 'master'
46+
condition({}, {
47+
env: {
48+
TRAVIS: 'true',
49+
TRAVIS_BRANCH: 'master'
50+
},
51+
options: {
52+
branch: 'master'
53+
}
4554
}, (err) => {
4655
tt.is(err, null)
4756
})
4857

49-
condition({}, {}, {}, {
50-
TRAVIS: 'true',
51-
TRAVIS_BRANCH: 'notmaster'
58+
condition({}, {
59+
env: {
60+
TRAVIS: 'true',
61+
TRAVIS_BRANCH: 'notmaster'
62+
},
63+
options: {
64+
branch: 'master'
65+
}
5266
}, (err) => {
5367
tt.ok(err instanceof SRError)
5468
tt.is(err.code, 'EBRANCHMISMATCH')
5569
})
5670

5771
condition({}, {
58-
release: {
72+
env: {
73+
TRAVIS: 'true',
74+
TRAVIS_BRANCH: 'master'
75+
},
76+
options: {
5977
branch: 'foo'
6078
}
61-
}, {}, {
62-
TRAVIS: 'true',
63-
TRAVIS_BRANCH: 'master'
6479
}, (err) => {
6580
tt.ok(err instanceof SRError)
6681
tt.is(err.code, 'EBRANCHMISMATCH')
@@ -70,29 +85,44 @@ test('raise errors in travis environment', (t) => {
7085
t.test('supports travis_after_all', (tt) => {
7186
tt.plan(5)
7287

73-
condition({}, {}, {}, {
74-
TRAVIS: 'true',
75-
TRAVIS_BRANCH: 'master',
76-
BUILD_LEADER: 'YES',
77-
BUILD_AGGREGATE_STATUS: 'others_succeeded'
88+
condition({}, {
89+
env: {
90+
TRAVIS: 'true',
91+
TRAVIS_BRANCH: 'master',
92+
BUILD_LEADER: 'YES',
93+
BUILD_AGGREGATE_STATUS: 'others_succeeded'
94+
},
95+
options: {
96+
branch: 'master'
97+
}
7898
}, (err) => {
7999
tt.is(err, null)
80100
})
81101

82-
condition({}, {}, {}, {
83-
TRAVIS: 'true',
84-
TRAVIS_BRANCH: 'master',
85-
BUILD_MINION: 'YES'
102+
condition({}, {
103+
env: {
104+
TRAVIS: 'true',
105+
TRAVIS_BRANCH: 'master',
106+
BUILD_MINION: 'YES'
107+
},
108+
options: {
109+
branch: 'master'
110+
}
86111
}, (err) => {
87112
tt.ok(err instanceof SRError)
88113
tt.is(err.code, 'ENOBUILDLEADER')
89114
})
90115

91-
condition({}, {}, {}, {
92-
TRAVIS: 'true',
93-
TRAVIS_BRANCH: 'master',
94-
BUILD_LEADER: 'YES',
95-
BUILD_AGGREGATE_STATUS: 'others_failed'
116+
condition({}, {
117+
env: {
118+
TRAVIS: 'true',
119+
TRAVIS_BRANCH: 'master',
120+
BUILD_LEADER: 'YES',
121+
BUILD_AGGREGATE_STATUS: 'others_failed'
122+
},
123+
options: {
124+
branch: 'master'
125+
}
96126
}, (err) => {
97127
tt.ok(err instanceof SRError)
98128
tt.is(err.code, 'EOTHERSFAILED')

0 commit comments

Comments
 (0)