forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-to-firebase.spec.js
422 lines (397 loc) · 13.3 KB
/
deploy-to-firebase.spec.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#!/usr/bin/env node
'use strict';
const {execSync} = require('child_process');
const {
computeDeploymentsInfo,
computeInputVars,
computeMajorVersion,
getLatestCommit,
getMostRecentMinorBranch,
} = require('./deploy-to-firebase');
describe('deploy-to-firebase:', () => {
// Pre-computed values to avoid unnecessary re-computations.
const mostRecentMinorBranch = getMostRecentMinorBranch();
const latestCommits = {
master: getLatestCommit('master'),
'2.1.x': getLatestCommit('2.1.x'),
'2.4.x': getLatestCommit('2.4.x'),
'4.3.x': getLatestCommit('4.3.x'),
'4.4.x': getLatestCommit('4.4.x'),
'9.1.x': getLatestCommit('9.1.x'),
[mostRecentMinorBranch]: getLatestCommit(mostRecentMinorBranch),
};
// Helpers
const jsonFunctionReplacer = (_key, val) =>
(typeof val === 'function') ? `function:${val.name}` : val;
const getDeploymentsInfoFor = env => {
const deploymentsInfo = computeDeploymentsInfo(computeInputVars(env));
return JSON.parse(JSON.stringify(deploymentsInfo, jsonFunctionReplacer));
};
it('master - skip deploy - not angular', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'notangular',
})).toEqual([
{
skipped: true,
reason: 'Skipping deploy because this is not angular/angular.',
},
]);
});
it('master - skip deploy - angular fork', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'notangular',
CI_REPO_NAME: 'angular',
})).toEqual([
{
skipped: true,
reason: 'Skipping deploy because this is not angular/angular.',
},
]);
});
it('master - skip deploy - pull request', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'true',
})).toEqual([
{
skipped: true,
reason: 'Skipping deploy because this is a PR build.',
},
]);
});
it('master - deploy success', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: 'master',
CI_COMMIT: latestCommits.master,
})).toEqual([
{
deployEnv: 'next',
projectId: 'angular-io',
siteId: 'next-angular-io-site',
deployedUrl: 'https://next.angular.io/',
preDeployActions: ['function:build', 'function:checkPayloadSize'],
postDeployActions: ['function:testPwaScore'],
},
]);
});
it('master - skip deploy - commit not HEAD', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: 'master',
CI_COMMIT: 'DUMMY_TEST_COMMIT',
})).toEqual([
{
skipped: true,
reason:
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
`(${latestCommits.master}).`,
},
]);
});
it('stable - deploy success - active RC', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '4.3.x',
CI_STABLE_BRANCH: '4.3.x',
CI_COMMIT: latestCommits['4.3.x'],
})).toEqual([
{
deployEnv: 'stable',
projectId: 'angular-io',
siteId: 'v4-angular-io-site',
deployedUrl: 'https://angular.io/',
preDeployActions: ['function:build', 'function:checkPayloadSize'],
postDeployActions: ['function:testPwaScore'],
},
]);
});
it('stable - deploy success - no active RC', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: mostRecentMinorBranch,
CI_STABLE_BRANCH: mostRecentMinorBranch,
CI_COMMIT: latestCommits[mostRecentMinorBranch],
})).toEqual([
{
deployEnv: 'stable',
projectId: 'angular-io',
siteId: `v${computeMajorVersion(mostRecentMinorBranch)}-angular-io-site`,
deployedUrl: 'https://angular.io/',
preDeployActions: ['function:build', 'function:checkPayloadSize'],
postDeployActions: ['function:testPwaScore'],
},
{
deployEnv: 'stable',
projectId: 'angular-io',
siteId: 'rc-angular-io-site',
deployedUrl: 'https://rc.angular.io/',
preDeployActions: ['function:removeServiceWorker', 'function:redirectToAngularIo'],
postDeployActions: ['function:testNoActiveRcDeployment'],
},
]);
});
it('stable - skip deploy - commit not HEAD', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '4.3.x',
CI_STABLE_BRANCH: '4.3.x',
CI_COMMIT: 'DUMMY_TEST_COMMIT',
})).toEqual([
{
skipped: true,
reason:
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
`(${latestCommits['4.3.x']}).`,
},
]);
});
it('archive - deploy success', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '2.4.x',
CI_STABLE_BRANCH: '4.3.x',
CI_COMMIT: latestCommits['2.4.x'],
})).toEqual([
{
deployEnv: 'archive',
projectId: 'angular-io',
siteId: 'v2-angular-io-site',
deployedUrl: 'https://v2.angular.io/',
preDeployActions: ['function:build', 'function:checkPayloadSize'],
postDeployActions: ['function:testPwaScore'],
},
]);
});
// v9 used to be special-cased, because it was piloting the Firebase hosting "multisites" setup.
// See https://angular-team.atlassian.net/browse/DEV-125 for more info.
it('archive - deploy success (no special case for v9)', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '9.1.x',
CI_STABLE_BRANCH: '10.0.x',
CI_COMMIT: latestCommits['9.1.x'],
})).toEqual([
{
deployEnv: 'archive',
projectId: 'angular-io',
siteId: 'v9-angular-io-site',
deployedUrl: 'https://v9.angular.io/',
preDeployActions: ['function:build', 'function:checkPayloadSize'],
postDeployActions: ['function:testPwaScore'],
},
]);
});
it('archive - skip deploy - commit not HEAD', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '2.4.x',
CI_STABLE_BRANCH: '4.3.x',
CI_COMMIT: 'DUMMY_TEST_COMMIT',
})).toEqual([
{
skipped: true,
reason:
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
`(${latestCommits['2.4.x']}).`,
},
]);
});
it('archive - skip deploy - major same as stable, minor lower than stable', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '2.1.x',
CI_STABLE_BRANCH: '2.2.x',
CI_COMMIT: latestCommits['2.1.x'],
})).toEqual([
{
skipped: true,
reason:
'Skipping deploy of branch "2.1.x" to Firebase.\n' +
'There is a more recent branch with the same major version: "2.4.x"',
},
]);
});
it('archive - skip deploy - major lower than stable, minor not highest for major', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '2.1.x',
CI_STABLE_BRANCH: '4.3.x',
CI_COMMIT: latestCommits['2.1.x'],
})).toEqual([
{
skipped: true,
reason:
'Skipping deploy of branch "2.1.x" to Firebase.\n' +
'There is a more recent branch with the same major version: "2.4.x"',
},
]);
});
it('rc - deploy success - major higher than stable', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: mostRecentMinorBranch,
CI_STABLE_BRANCH: '2.2.x',
CI_COMMIT: latestCommits[mostRecentMinorBranch],
})).toEqual([
{
deployEnv: 'rc',
projectId: 'angular-io',
siteId: 'rc-angular-io-site',
deployedUrl: 'https://rc.angular.io/',
preDeployActions: ['function:build', 'function:checkPayloadSize'],
postDeployActions: ['function:testPwaScore'],
},
]);
});
it('rc - deploy success - major same as stable, minor highest for major', () => {
// Create a stable branch name that has the same major and lower minor than
// `mostRecentMinorBranch`.
// NOTE: Since `mostRecentMinorBranch` can have a minor version of `0`, we may end up with `-1`
// as the minor version for stable. This is a hack, but it works ¯\_(ツ)_/¯
const stableBranch = mostRecentMinorBranch.replace(
/^(\d+)\.(\d+)\.x$/, (_, major, minor) => `${major}.${minor - 1}.x`);
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: mostRecentMinorBranch,
CI_STABLE_BRANCH: stableBranch,
CI_COMMIT: latestCommits[mostRecentMinorBranch],
})).toEqual([
{
deployEnv: 'rc',
projectId: 'angular-io',
siteId: 'rc-angular-io-site',
deployedUrl: 'https://rc.angular.io/',
preDeployActions: ['function:build', 'function:checkPayloadSize'],
postDeployActions: ['function:testPwaScore'],
},
]);
});
it('rc - skip deploy - commit not HEAD', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: mostRecentMinorBranch,
CI_STABLE_BRANCH: '2.2.x',
CI_COMMIT: 'DUMMY_TEST_COMMIT',
})).toEqual([
{
skipped: true,
reason:
'Skipping deploy because DUMMY_TEST_COMMIT is not the latest commit ' +
`(${latestCommits[mostRecentMinorBranch]}).`,
},
]);
});
it('rc - skip deploy - major same as stable, minor not highest for major', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '2.1.x',
CI_STABLE_BRANCH: '2.0.x',
CI_COMMIT: latestCommits['2.1.x'],
})).toEqual([
{
skipped: true,
reason:
'Skipping deploy of branch "2.1.x" to Firebase.\n' +
'There is a more recent branch with the same major version: "2.4.x"',
},
]);
});
it('rc - skip deploy - major higher than stable, minor not highest for major', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '4.3.x',
CI_STABLE_BRANCH: '2.4.x',
CI_COMMIT: latestCommits['4.3.x'],
})).toEqual([
{
skipped: true,
reason:
'Skipping deploy of branch "4.3.x" to Firebase.\n' +
'There is a more recent branch with the same major version: "4.4.x"',
},
]);
});
it('rc - skip deploy - major higher than stable but not highest, minor highest for major', () => {
expect(getDeploymentsInfoFor({
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: '4.4.x',
CI_STABLE_BRANCH: '2.4.x',
CI_COMMIT: latestCommits['4.4.x'],
})).toEqual([
{
skipped: true,
reason:
'Skipping deploy of branch "4.4.x" to Firebase.\n' +
'This branch has an equal or higher major version than the stable branch ("2.4.x") ' +
'and is not the most recent minor branch.',
},
]);
});
it('integration - should run the main script without error', () => {
// NOTE:
// This test executes a new instance of the `deploy-to-firebase.js` script on a separate process
// and thus does not share the `getRemoteRefs()` cache. To improve stability, we retrieve the
// latest commit from master ignoring any cached entries.
const latestCommitOnMaster = getLatestCommit('master', {retrieveFromCache: false});
const cmd = `"${process.execPath}" "${__dirname}/deploy-to-firebase" --dry-run`;
const env = {
CI_REPO_OWNER: 'angular',
CI_REPO_NAME: 'angular',
CI_PULL_REQUEST: 'false',
CI_BRANCH: 'master',
CI_COMMIT: latestCommitOnMaster,
};
const result = execSync(cmd, {encoding: 'utf8', env}).trim();
expect(result).toBe(
'Total deployments: 1\n' +
'\n' +
'\n' +
'\n' +
'Deployment 1 of 1\n' +
'-----------------\n' +
'Git branch : master\n' +
`Git commit : ${latestCommitOnMaster}\n` +
'Build/deploy mode : next\n' +
'Firebase project : angular-io\n' +
'Firebase site : next-angular-io-site\n' +
'Pre-deploy actions : build, checkPayloadSize\n' +
'Post-deploy actions : testPwaScore\n' +
'Deployment URLs : https://next.angular.io/\n' +
' https://next-angular-io-site.web.app/');
});
});