Skip to content

Commit 4eed12b

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Fix RNTestProject testing on Android (#41172)
Summary: While releasing RN 0.73.0-RC3, we relaized that the e2e test script was bugged for Android when used to test RNTestProject with the `-c` option. There were 2 problems: - The downloaded maven-local was not actually used because it doesn't work with a zip. (We were always downloading a version from Maven) - The versions of React Native between maven-local and the locally packaged React Native were different. This change fixes the script by: - Downloading maven-local - Unzipping maven-local and passing the new folder to the Android app - Downloading the React Native version that has been packaged in CI By unzipping maven-local and using the unzipped folder, we make sure that Android is actually using the local repository. By downloading both the packaged react native and the maven-local from the same CI workflow, we ensure that the versions are aligned. This also speeds-up further the Android testing. While running this change, we also moved the `pod install` step inside the `if (iOS)` branch, so we do not install Cocoapods if we need to test Android. ## Changelog: [Internal] - Fix Android E2E test script when downloading artefacts from CI Pull Request resolved: #41172 Test Plan: Tested locally on both main and 0.73-stable, on both Android and iOS Reviewed By: cortinico Differential Revision: D50651448 Pulled By: cipolleschi fbshipit-source-id: 70a9ed19072119d19c5388e8a4309d7333a08e13
1 parent 3648886 commit 4eed12b

File tree

3 files changed

+43
-45
lines changed

3 files changed

+43
-45
lines changed

scripts/circle-ci-artifacts-utils.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ async function _findUrlForJob(jobName, artifactPath) {
128128
_throwIfJobIsUnsuccessful(job);
129129

130130
const artifacts = await _getJobsArtifacts(job.job_number);
131-
return artifacts.find(artifact => artifact.path.indexOf(artifactPath) > -1)
132-
.url;
131+
let artifact = artifacts.find(a => a.path.indexOf(artifactPath) > -1);
132+
if (!artifact) {
133+
throw new Error(`I could not find the artifact with path ${artifactPath}`);
134+
}
135+
return artifact.url;
133136
}
134137

135138
function _throwIfJobIsNull(job) {
@@ -156,6 +159,17 @@ async function artifactURLForMavenLocal() {
156159
return _findUrlForJob('build_npm_package', 'maven-local.zip');
157160
}
158161

162+
async function artifactURLForReactNative() {
163+
let shortCommit = exec('git rev-parse HEAD', {silent: true})
164+
.toString()
165+
.trim()
166+
.slice(0, 9);
167+
return _findUrlForJob(
168+
'build_npm_package',
169+
`react-native-1000.0.0-${shortCommit}.tgz`,
170+
);
171+
}
172+
159173
async function artifactURLForHermesRNTesterAPK(emulatorArch) {
160174
return _findUrlForJob(
161175
'test_android',
@@ -182,5 +196,6 @@ module.exports = {
182196
artifactURLForHermesRNTesterAPK,
183197
artifactURLForMavenLocal,
184198
artifactURLHermesDebug,
199+
artifactURLForReactNative,
185200
baseTmpPath,
186201
};

scripts/test-e2e-local.js

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const {exec, pushd, popd, pwd, cd, sed} = require('shelljs');
2020
const updateTemplatePackage = require('./update-template-package');
2121
const yargs = require('yargs');
2222
const path = require('path');
23-
const fs = require('fs');
2423

2524
const {
2625
checkPackagerRunning,
@@ -189,15 +188,12 @@ async function testRNTestProject(circleCIArtifacts) {
189188
// in local testing, 1000.0.0 mean we are on main, every other case means we are
190189
// working on a release version
191190
const buildType = baseVersion !== '1000.0.0' ? 'release' : 'dry-run';
191+
const shortCommit = exec('git rev-parse HEAD', {silent: true})
192+
.toString()
193+
.trim()
194+
.slice(0, 9);
192195

193-
// we need to add the unique timestamp to avoid npm/yarn to use some local caches
194-
const dateIdentifier = new Date()
195-
.toISOString()
196-
.slice(0, -8)
197-
.replace(/[-:]/g, '')
198-
.replace(/[T]/g, '-');
199-
200-
const releaseVersion = `${baseVersion}-${dateIdentifier}`;
196+
const releaseVersion = `1000.0.0-${shortCommit}`;
201197

202198
// Prepare some variables for later use
203199
const repoRoot = pwd();
@@ -206,7 +202,7 @@ async function testRNTestProject(circleCIArtifacts) {
206202

207203
const mavenLocalPath =
208204
circleCIArtifacts != null
209-
? path.join(circleCIArtifacts.baseTmpPath(), 'maven-local.zip')
205+
? path.join(circleCIArtifacts.baseTmpPath(), 'maven-local')
210206
: '/private/tmp/maven-local';
211207
const hermesPath = await prepareArtifacts(
212208
circleCIArtifacts,
@@ -218,38 +214,21 @@ async function testRNTestProject(circleCIArtifacts) {
218214
);
219215

220216
updateTemplatePackage({
221-
'react-native': `file:${localNodeTGZPath}`,
217+
'react-native': `file://${localNodeTGZPath}`,
222218
});
223219

224-
// create locally the node module
225-
exec('npm pack --pack-destination ', {cwd: reactNativePackagePath});
226-
227-
// node pack does not creates a version of React Native with the right name on main.
228-
// Let's add some defensive programming checks:
229-
if (!fs.existsSync(localNodeTGZPath)) {
230-
const tarfile = fs
231-
.readdirSync(reactNativePackagePath)
232-
.find(name => name.startsWith('react-native-') && name.endsWith('.tgz'));
233-
if (!tarfile) {
234-
throw new Error("Couldn't find a zipped version of react-native");
235-
}
236-
exec(
237-
`cp ${path.join(reactNativePackagePath, tarfile)} ${localNodeTGZPath}`,
238-
);
239-
}
240-
241220
pushd('/tmp/');
242221
// need to avoid the pod install step - we'll do it later
243222
exec(
244-
`node ${reactNativePackagePath}/cli.js init RNTestProject --template ${localNodeTGZPath} --skip-install`,
223+
`node ${reactNativePackagePath}/cli.js init RNTestProject --template ${reactNativePackagePath} --skip-install`,
245224
);
246225

247226
cd('RNTestProject');
248227
exec('yarn install');
249228

250229
// need to do this here so that Android will be properly setup either way
251230
exec(
252-
`echo "react.internal.mavenLocalRepo=${mavenLocalPath}" >> android/gradle.properties`,
231+
`echo "react.internal.mavenLocalRepo=${mavenLocalPath}/tmp/maven-local" >> android/gradle.properties`,
253232
);
254233

255234
// Update gradle properties to set Hermes as false
@@ -262,18 +241,17 @@ async function testRNTestProject(circleCIArtifacts) {
262241
);
263242
}
264243

265-
// doing the pod install here so that it's easier to play around RNTestProject
266-
cd('ios');
267-
exec('bundle install');
268-
exec(
269-
`HERMES_ENGINE_TARBALL_PATH=${hermesPath} USE_HERMES=${
270-
argv.hermes ? 1 : 0
271-
} bundle exec pod install --ansi`,
272-
);
273-
274-
cd('..');
275-
276244
if (argv.platform === 'iOS') {
245+
// doing the pod install here so that it's easier to play around RNTestProject
246+
cd('ios');
247+
exec('bundle install');
248+
exec(
249+
`HERMES_ENGINE_TARBALL_PATH=${hermesPath} USE_HERMES=${
250+
argv.hermes ? 1 : 0
251+
} bundle exec pod install --ansi`,
252+
);
253+
254+
cd('..');
277255
exec('yarn ios');
278256
} else {
279257
// android

scripts/testing-utils.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,21 @@ async function downloadArtifactsFromCircleCI(
170170
) {
171171
const mavenLocalURL = await circleCIArtifacts.artifactURLForMavenLocal();
172172
const hermesURL = await circleCIArtifacts.artifactURLHermesDebug();
173+
const reactNativeURL = await circleCIArtifacts.artifactURLForReactNative();
173174

174175
const hermesPath = path.join(
175176
circleCIArtifacts.baseTmpPath(),
176177
'hermes-ios-debug.tar.gz',
177178
);
178179

179-
console.info('[Download] Maven Local Artifacts');
180-
circleCIArtifacts.downloadArtifact(mavenLocalURL, mavenLocalPath);
180+
console.info(`[Download] Maven Local Artifacts from ${mavenLocalURL}`);
181+
const mavenLocalZipPath = `${mavenLocalPath}.zip`;
182+
circleCIArtifacts.downloadArtifact(mavenLocalURL, mavenLocalZipPath);
183+
exec(`unzip -oq ${mavenLocalZipPath} -d ${mavenLocalPath}`);
181184
console.info('[Download] Hermes');
182185
circleCIArtifacts.downloadArtifact(hermesURL, hermesPath);
186+
console.info(`[Download] React Native from ${reactNativeURL}`);
187+
circleCIArtifacts.downloadArtifact(reactNativeURL, localNodeTGZPath);
183188

184189
return hermesPath;
185190
}

0 commit comments

Comments
 (0)