This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
release-please.js
364 lines (304 loc) · 10 KB
/
release-please.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
const { describe, it, beforeEach, afterEach } = require('mocha')
const action = require('../')
const assert = require('assert')
const core = require('@actions/core')
const sinon = require('sinon')
const { factory, GitHubRelease } = require('release-please/build/src')
const { Manifest } = require('release-please/build/src/manifest')
const { Node } = require('release-please/build/src/releasers/node')
// As defined in action.yml
const defaultInput = {
fork: 'false',
clean: 'true',
'bump-minor-pre-major': 'false',
path: '',
'monorepo-tags': 'false',
'changelog-path': '',
'changelog-types': '',
command: '',
'version-file': '',
'default-branch': '',
// eslint-disable-next-line no-template-curly-in-string
'pull-request-title-pattern': 'chore${scope}: release${component} ${version}'
}
let input
let output
const sandbox = sinon.createSandbox()
process.env.GITHUB_REPOSITORY = 'google/cloud'
describe('release-please-action', () => {
beforeEach(() => {
input = {}
output = {}
core.setOutput = (name, value) => {
output[name] = value
}
core.getInput = name => {
if (input[name] === undefined || input[name] == null) {
return defaultInput[name]
} else {
return input[name]
}
}
})
afterEach(() => {
sandbox.restore()
})
const trueValue = ['true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 'y', 'Y', 'on', 'On', 'ON']
const falseValue = ['false', 'False', 'FALSE', 'no', 'No', 'NO', 'n', 'N', 'off', 'Off', 'OFF']
trueValue.forEach(value => {
it(`get the boolean true with the input of '${value}'`, () => {
input = {
fork: value
}
const actual = action.getBooleanInput('fork')
assert.strictEqual(actual, true)
})
})
falseValue.forEach(value => {
it(`get the boolean with the input of '${value}'`, () => {
input = {
fork: value
}
const actual = action.getBooleanInput('fork')
assert.strictEqual(actual, false)
})
})
it('get an error when inputting the wrong boolean value', () => {
input = {
fork: 'wrong'
}
assert.throws(
() => {
action.getBooleanInput('fork')
},
{ name: 'TypeError', message: "Wrong boolean value of the input 'fork'" }
)
})
it('sets pull pullRequestTitlePattern to undefined, if empty string provided', async () => {
input = {
'release-type': 'node',
// eslint-disable-next-line no-template-curly-in-string
'pull-request-title-pattern': ''
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
await action.main()
sinon.assert.calledOnce(githubReleasePRStub)
sinon.assert.calledWith(
githubReleasePRStub,
'release-pr',
// eslint-disable-next-line no-template-curly-in-string
sinon.match.hasOwn('pullRequestTitlePattern', undefined)
)
})
it('opens PR with custom changelogSections', async () => {
input = {
'release-type': 'node',
'changelog-types':
'[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
await action.main()
sinon.assert.calledOnce(githubReleasePRStub)
sinon.assert.calledWith(
githubReleasePRStub,
'release-pr',
sinon.match.hasOwn(
'changelogSections',
JSON.parse(
'[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
)
)
)
})
it('both opens PR to the default branch and tags GitHub releases by default', async () => {
input = {
'release-type': 'node'
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
const githubReleaseStub = runCommandStub.withArgs('github-release').returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
await action.main()
sinon.assert.calledOnce(githubReleaseStub)
sinon.assert.calledOnce(githubReleasePRStub)
sinon.assert.calledWith(
githubReleaseStub,
'github-release',
sinon.match.hasOwn('defaultBranch', undefined)
)
sinon.assert.calledWith(
githubReleasePRStub,
'release-pr',
sinon.match.hasOwn('defaultBranch', undefined)
)
assert.deepStrictEqual(output, {
release_created: true,
upload_url: 'http://example.com',
tag_name: 'v1.0.0',
pr: 25
})
})
it('both opens PR to a different default branch and tags GitHub releases by default', async () => {
input = {
'release-type': 'node',
'default-branch': 'dev'
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
const githubReleaseStub = runCommandStub.withArgs('github-release').returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
await action.main()
sinon.assert.calledOnce(githubReleaseStub)
sinon.assert.calledWith(
githubReleaseStub,
'github-release',
sinon.match.hasOwn('defaultBranch', 'dev')
)
sinon.assert.calledOnce(githubReleasePRStub)
sinon.assert.calledWith(
githubReleasePRStub,
'release-pr',
sinon.match.hasOwn('defaultBranch', 'dev')
)
assert.deepStrictEqual(output, {
release_created: true,
upload_url: 'http://example.com',
tag_name: 'v1.0.0',
pr: 25
})
})
it('only opens PR, if command set to release-pr', async () => {
input = {
'release-type': 'node',
command: 'release-pr'
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
const githubReleaseStub = runCommandStub.withArgs('github-release').returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
await action.main()
sinon.assert.notCalled(githubReleaseStub)
sinon.assert.calledOnce(githubReleasePRStub)
})
it('only creates GitHub release, if command set to github-release', async () => {
input = {
'release-type': 'node',
command: 'github-release'
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
const githubReleaseStub = runCommandStub.withArgs('github-release').returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
const githubReleasePRStub = runCommandStub.withArgs('release-pr').returns(25)
await action.main()
sinon.assert.calledOnce(githubReleaseStub)
sinon.assert.notCalled(githubReleasePRStub)
})
it('sets appropriate outputs when GitHub release created', async () => {
const expected = {
release_created: true,
upload_url: 'http://example.com',
html_url: 'http://example2.com',
tag_name: 'v1.0.0',
major: 1,
minor: 2,
patch: 3,
version: 'v1.2.3',
sha: 'abc123',
pr: 33
}
input = {
'release-type': 'node',
command: 'github-release'
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
runCommandStub.withArgs('github-release').returns(expected)
runCommandStub.withArgs('release-pr').returns(25)
await action.main()
assert.deepStrictEqual(output, expected)
})
it('sets appropriate outputs when release PR opened', async () => {
input = {
'release-type': 'node',
command: 'release-pr'
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
runCommandStub.withArgs('release-pr').returns(95)
await action.main()
assert.strictEqual(output.pr, 95)
})
it('does not set PR output, when no release PR is returned', async () => {
input = {
'release-type': 'node',
command: 'release-pr'
}
const runCommandStub = sandbox.stub(factory, 'runCommand')
runCommandStub.withArgs('release-pr').returns(undefined)
await action.main()
assert.strictEqual(Object.hasOwnProperty.call(output, 'pr'), false)
})
it('creates and runs a ReleasePR instance, using factory', async () => {
let maybeReleasePR
sandbox.replace(factory, 'call', runnable => {
maybeReleasePR = runnable
})
input = {
'release-type': 'node',
command: 'release-pr'
}
await action.main()
assert.ok(maybeReleasePR instanceof Node)
})
it('creates and runs a GitHubRelease, using factory', async () => {
let maybeGitHubRelease
sandbox.replace(factory, 'call', runnable => {
maybeGitHubRelease = runnable
})
input = {
'release-type': 'node',
command: 'github-release'
}
await action.main()
assert.ok(maybeGitHubRelease instanceof GitHubRelease)
})
it('creates and runs a Manifest, using factory', async () => {
let maybeManifest
sandbox.replace(factory, 'call', runnable => {
maybeManifest = runnable
})
input = { command: 'manifest' }
await action.main()
assert.ok(maybeManifest instanceof Manifest)
})
it('opens PR creates GitHub releases by default for manifest', async () => {
input = { command: 'manifest' }
const runCommandStub = sandbox.stub(factory, 'runCommand')
const manifestReleaseStub = runCommandStub.withArgs('manifest-release').resolves(
{
'path/pkgA':
{
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
}
})
const manifestReleasePRStub = runCommandStub.withArgs('manifest-pr').returns(25)
await action.main()
sinon.assert.calledOnce(manifestReleaseStub)
sinon.assert.calledOnce(manifestReleasePRStub)
assert.deepStrictEqual(output, {
releases_created: true,
'path/pkgA--upload_url': 'http://example.com',
'path/pkgA--tag_name': 'v1.0.0',
pr: 25
})
})
})