Skip to content

Commit 119ab33

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Port changes in the release testing script from the release branch (facebook#45174)
Summary: Pull Request resolved: facebook#45174 As per title, this port bck to main the changes we made in the release testing script. ## Changelog: [Internal] - Update release testing script to work with the new template Reviewed By: blakef Differential Revision: D59054045 fbshipit-source-id: 0e93c2db94499407845b4fb2c98c8b44310e770f
1 parent cf8d3f8 commit 119ab33

File tree

3 files changed

+75
-36
lines changed

3 files changed

+75
-36
lines changed

scripts/e2e/init-template-e2e.js

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
'use strict';
1313

14+
/*:: import type {ProjectInfo} from '../utils/monorepo'; */
15+
1416
const {retry} = require('../circleci/retry');
1517
const {REPO_ROOT} = require('../consts');
1618
const {getPackages} = require('../utils/monorepo');
@@ -22,12 +24,12 @@ const {
2224
const {parseArgs} = require('@pkgjs/parseargs');
2325
const chalk = require('chalk');
2426
const {execSync} = require('child_process');
27+
const fs = require('fs');
2528
const path = require('path');
2629

2730
const config = {
2831
options: {
2932
projectName: {type: 'string'},
30-
templatePath: {type: 'string'},
3133
directory: {type: 'string'},
3234
verbose: {type: 'boolean', default: false},
3335
help: {type: 'boolean'},
@@ -56,10 +58,10 @@ async function main() {
5658
should not be committed.
5759
5860
Options:
59-
--projectName The name of the new React Native project.
60-
--templatePath The absolute path to the folder containing the template.
61-
--directory The absolute path to the target project directory.
62-
--verbose Print additional output. Default: false.
61+
--projectName The name of the new React Native project.
62+
--directory The absolute path to the target project directory.
63+
--pathToLocalReactNative The absolute path to the local react-native package.
64+
--verbose Print additional output. Default: false.
6365
`);
6466
return;
6567
}
@@ -74,10 +76,10 @@ async function main() {
7476
async function initNewProjectFromSource(
7577
{
7678
projectName,
77-
templatePath,
7879
directory,
80+
pathToLocalReactNative = null,
7981
verbose = false,
80-
} /*: {projectName: string, templatePath: string, directory: string, verbose?: boolean} */,
82+
} /*: {projectName: string, directory: string, pathToLocalReactNative?: ?string, verbose?: boolean} */,
8183
) {
8284
console.log('Starting local npm proxy (Verdaccio)');
8385
const verdaccioPid = setupVerdaccio();
@@ -117,9 +119,9 @@ async function initNewProjectFromSource(
117119

118120
console.log('Running react-native init without install');
119121
execSync(
120-
`node ./packages/react-native/cli.js init ${projectName} \
122+
`npx @react-native-community/cli@next init ${projectName} \
121123
--directory ${directory} \
122-
--template ${templatePath} \
124+
--version 0.75.0-rc.2 \
123125
--verbose \
124126
--pm npm \
125127
--skip-install`,
@@ -131,6 +133,9 @@ async function initNewProjectFromSource(
131133
);
132134
console.log('\nDone ✅');
133135

136+
_updateScopedPackages(packages, directory);
137+
_updateReactNativeInTemplateIfNeeded(pathToLocalReactNative, directory);
138+
134139
console.log('Installing project dependencies');
135140
await installProjectUsingProxy(directory);
136141
console.log('Done ✅');
@@ -169,6 +174,61 @@ async function installProjectUsingProxy(cwd /*: string */) {
169174
}
170175
}
171176

177+
function _updateScopedPackages(
178+
packages /*: ProjectInfo */,
179+
directory /*: string */,
180+
) {
181+
console.log(
182+
'Updating the scoped packagesto match the version published in Verdaccio',
183+
);
184+
185+
// Packages are updated in a lockstep and all with the same version.
186+
// Pick the version from the first package
187+
const version = packages[Object.keys(packages)[0]].packageJson.version;
188+
189+
// Update scoped packages which starts with @react-native
190+
const appPackageJsonPath = path.join(directory, 'package.json');
191+
const appPackageJson = JSON.parse(
192+
fs.readFileSync(appPackageJsonPath, 'utf8'),
193+
);
194+
195+
for (const [key, _] of Object.entries(appPackageJson.dependencies)) {
196+
if (key.startsWith('@react-native')) {
197+
appPackageJson.dependencies[key] = version;
198+
}
199+
}
200+
for (const [key, _] of Object.entries(appPackageJson.devDependencies)) {
201+
if (key.startsWith('@react-native')) {
202+
appPackageJson.devDependencies[key] = version;
203+
}
204+
}
205+
206+
fs.writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2));
207+
208+
console.log('Done ✅');
209+
}
210+
211+
function _updateReactNativeInTemplateIfNeeded(
212+
pathToLocalReactNative /*: ?string */,
213+
directory /*: string */,
214+
) {
215+
if (pathToLocalReactNative != null) {
216+
console.log('Updating the template version to local react-native');
217+
// Update template version.
218+
const appPackageJsonPath = path.join(directory, 'package.json');
219+
const appPackageJson = JSON.parse(
220+
fs.readFileSync(appPackageJsonPath, 'utf8'),
221+
);
222+
appPackageJson.dependencies['react-native'] =
223+
`file:${pathToLocalReactNative}`;
224+
fs.writeFileSync(
225+
appPackageJsonPath,
226+
JSON.stringify(appPackageJson, null, 2),
227+
);
228+
console.log('Done ✅');
229+
}
230+
}
231+
172232
module.exports = {
173233
initNewProjectFromSource,
174234
};

scripts/release-testing/test-e2e-local.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const {
2424
launchPackagerInSeparateWindow,
2525
maybeLaunchAndroidEmulator,
2626
prepareArtifacts,
27-
setupCircleCIArtifacts,
2827
setupGHAArtifacts,
2928
} = require('./utils/testing-utils');
3029
const chalk = require('chalk');
@@ -78,7 +77,7 @@ const argv = yargs
7877
* - @onReleaseBranch whether we are on a release branch or not
7978
*/
8079
async function testRNTesterIOS(
81-
ciArtifacts /*: Unwrap<ReturnType<typeof setupCircleCIArtifacts>> */,
80+
ciArtifacts /*: Unwrap<ReturnType<typeof setupGHAArtifacts>> */,
8281
onReleaseBranch /*: boolean */,
8382
) {
8483
console.info(
@@ -130,7 +129,7 @@ async function testRNTesterIOS(
130129
* - @circleCIArtifacts manager object to manage all the download of CircleCIArtifacts. If null, it will fallback not to use them.
131130
*/
132131
async function testRNTesterAndroid(
133-
ciArtifacts /*: Unwrap<ReturnType<typeof setupCircleCIArtifacts>> */,
132+
ciArtifacts /*: Unwrap<ReturnType<typeof setupGHAArtifacts>> */,
134133
) {
135134
maybeLaunchAndroidEmulator();
136135

@@ -206,7 +205,7 @@ async function testRNTesterAndroid(
206205
* - @onReleaseBranch whether we are on a release branch or not
207206
*/
208207
async function testRNTester(
209-
circleCIArtifacts /*:Unwrap<ReturnType<typeof setupCircleCIArtifacts>> */,
208+
circleCIArtifacts /*:Unwrap<ReturnType<typeof setupGHAArtifacts>> */,
210209
onReleaseBranch /*: boolean */,
211210
) {
212211
// FIXME: make sure that the commands retains colors
@@ -225,7 +224,7 @@ async function testRNTester(
225224
// === RNTestProject === //
226225

227226
async function testRNTestProject(
228-
ciArtifacts /*: Unwrap<ReturnType<typeof setupCircleCIArtifacts>> */,
227+
ciArtifacts /*: Unwrap<ReturnType<typeof setupGHAArtifacts>> */,
229228
) {
230229
console.info("We're going to test a fresh new RN project");
231230

@@ -244,11 +243,6 @@ async function testRNTestProject(
244243
const buildType = 'dry-run';
245244

246245
const reactNativePackagePath = `${REPO_ROOT}/packages/react-native`;
247-
const templateRepoFolder = '/tmp/template';
248-
const pathToTemplate = path.join(templateRepoFolder, 'template');
249-
250-
// Cleanup template clone folder
251-
exec(`rm -rf ${templateRepoFolder}`);
252246
const localNodeTGZPath = `${reactNativePackagePath}/react-native-${releaseVersion}.tgz`;
253247

254248
const mavenLocalPath =
@@ -286,21 +280,6 @@ async function testRNTestProject(
286280
}
287281
}
288282

289-
// Cloning the template repo
290-
// TODO: handle versioning of the template to make sure that we are downloading the right version of
291-
// the template, given a specific React Native version
292-
exec(
293-
`git clone https://github.com/react-native-community/template ${templateRepoFolder} --depth=1`,
294-
);
295-
296-
// Update template version.
297-
const appPackageJsonPath = path.join(pathToTemplate, 'package.json');
298-
const appPackageJson = JSON.parse(
299-
fs.readFileSync(appPackageJsonPath, 'utf8'),
300-
);
301-
appPackageJson.dependencies['react-native'] = `file:${newLocalNodeTGZ}`;
302-
fs.writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2));
303-
304283
pushd('/tmp/');
305284

306285
debug('Creating RNTestProject from template');
@@ -311,7 +290,7 @@ async function testRNTestProject(
311290
await initNewProjectFromSource({
312291
projectName: 'RNTestProject',
313292
directory: '/tmp/RNTestProject',
314-
templatePath: templateRepoFolder,
293+
pathToLocalReactNative: newLocalNodeTGZ,
315294
});
316295

317296
cd('RNTestProject');

scripts/utils/monorepo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type PackageInfo = {
4242
packageJson: PackageJson,
4343
};
4444
45-
type ProjectInfo = {
45+
export type ProjectInfo = {
4646
[packageName: string]: PackageInfo,
4747
};
4848
*/

0 commit comments

Comments
 (0)