forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-and-test.js
executable file
·227 lines (185 loc) · 5.96 KB
/
build-and-test.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
#!/usr/bin/env node
'use strict';
const chalk = require('chalk');
const {exec} = require('child-process-promise');
const inquirer = require('inquirer');
const {homedir} = require('os');
const {join, relative} = require('path');
const {DRY_RUN, ROOT_PATH} = require('./configuration');
const {
clear,
confirm,
confirmContinue,
execRead,
logger,
saveBuildMetadata,
} = require('./utils');
// This is the primary control function for this script.
async function main() {
clear();
await confirm('Have you run the prepare-release script?', () => {
const prepareReleaseScriptPath = join(__dirname, 'prepare-release.js');
const pathToPrint = relative(process.cwd(), prepareReleaseScriptPath);
console.log('Begin by running the prepare-release script:');
console.log(chalk.bold.green(' ' + pathToPrint));
});
const archivePath = await archiveGitRevision();
const buildID = await downloadLatestReactBuild();
await buildAndTestInlinePackage();
await buildAndTestStandalonePackage();
await buildAndTestExtensions();
saveBuildMetadata({archivePath, buildID});
printFinalInstructions();
}
async function archiveGitRevision() {
const desktopPath = join(homedir(), 'Desktop');
const archivePath = join(desktopPath, 'DevTools.tgz');
console.log(`Creating git archive at ${chalk.dim(archivePath)}`);
console.log('');
if (!DRY_RUN) {
await exec(`git archive main | gzip > ${archivePath}`, {cwd: ROOT_PATH});
}
return archivePath;
}
async function buildAndTestExtensions() {
const extensionsPackagePath = join(
ROOT_PATH,
'packages',
'react-devtools-extensions'
);
const buildExtensionsPromise = exec('yarn build', {
cwd: extensionsPackagePath,
});
await logger(
buildExtensionsPromise,
`Building browser extensions ${chalk.dim('(this may take a minute)')}`,
{
estimate: 60000,
}
);
console.log('');
console.log(`Extensions have been build for Chrome, Edge, and Firefox.`);
console.log('');
console.log('Smoke test each extension before continuing:');
console.log(` ${chalk.bold.green('cd ' + extensionsPackagePath)}`);
console.log('');
console.log(` ${chalk.dim('# Test Chrome extension')}`);
console.log(` ${chalk.bold.green('yarn test:chrome')}`);
console.log('');
console.log(` ${chalk.dim('# Test Edge extension')}`);
console.log(` ${chalk.bold.green('yarn test:edge')}`);
console.log('');
console.log(` ${chalk.dim('# Firefox Chrome extension')}`);
console.log(` ${chalk.bold.green('yarn test:firefox')}`);
await confirmContinue();
}
async function buildAndTestStandalonePackage() {
const corePackagePath = join(ROOT_PATH, 'packages', 'react-devtools-core');
const corePackageDest = join(corePackagePath, 'dist');
await exec(`rm -rf ${corePackageDest}`);
const buildCorePromise = exec('yarn build', {cwd: corePackagePath});
await logger(
buildCorePromise,
`Building ${chalk.bold('react-devtools-core')} package.`,
{
estimate: 25000,
}
);
const standalonePackagePath = join(ROOT_PATH, 'packages', 'react-devtools');
const safariFixturePath = join(
ROOT_PATH,
'fixtures',
'devtools',
'standalone',
'index.html'
);
console.log('');
console.log(
`Test the ${chalk.bold('react-devtools-core')} target before continuing:`
);
console.log(` ${chalk.bold.green('cd ' + standalonePackagePath)}`);
console.log(` ${chalk.bold.green('yarn start')}`);
console.log('');
console.log(
'The following fixture can be useful for testing Safari integration:'
);
console.log(` ${chalk.dim(safariFixturePath)}`);
await confirmContinue();
}
async function buildAndTestInlinePackage() {
const inlinePackagePath = join(
ROOT_PATH,
'packages',
'react-devtools-inline'
);
const inlinePackageDest = join(inlinePackagePath, 'dist');
await exec(`rm -rf ${inlinePackageDest}`);
const buildPromise = exec('yarn build', {cwd: inlinePackagePath});
await logger(
buildPromise,
`Building ${chalk.bold('react-devtools-inline')} package.`,
{
estimate: 10000,
}
);
const shellPackagePath = join(ROOT_PATH, 'packages', 'react-devtools-shell');
console.log('');
console.log(`Built ${chalk.bold('react-devtools-inline')} target.`);
console.log('');
console.log('Test this build before continuing:');
console.log(` ${chalk.bold.green('cd ' + shellPackagePath)}`);
console.log(` ${chalk.bold.green('yarn start')}`);
await confirmContinue();
}
async function downloadLatestReactBuild() {
const releaseScriptPath = join(ROOT_PATH, 'scripts', 'release');
const installPromise = exec('yarn install', {cwd: releaseScriptPath});
await logger(
installPromise,
`Installing release script dependencies. ${chalk.dim(
'(this may take a minute if CI is still running)'
)}`,
{
estimate: 5000,
}
);
console.log('');
const {commit} = await inquirer.prompt([
{
type: 'input',
name: 'commit',
message: 'Which React version (commit) should be used?',
default: 'main',
},
]);
console.log('');
const downloadScriptPath = join(
releaseScriptPath,
'download-experimental-build.js'
);
const downloadPromise = execRead(
`"${downloadScriptPath}" --commit=${commit}`
);
const output = await logger(
downloadPromise,
'Downloading React artifacts from CI.',
{estimate: 15000}
);
const match = output.match('--build=([0-9]+)');
if (match.length === 0) {
console.error(chalk.red(`No build ID found in "${output}"`));
process.exit(1);
}
const buildID = match[1];
console.log('');
console.log(`Downloaded artiacts for CI build ${chalk.bold(buildID)}.`);
return buildID;
}
function printFinalInstructions() {
const publishReleaseScriptPath = join(__dirname, 'publish-release.js');
const pathToPrint = relative(process.cwd(), publishReleaseScriptPath);
console.log('');
console.log('Continue by running the publish-release script:');
console.log(chalk.bold.green(' ' + pathToPrint));
}
main();