Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RNTestProject testing on Android #41378

Merged
merged 4 commits into from Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions scripts/circle-ci-artifacts-utils.js
Expand Up @@ -140,8 +140,11 @@ async function _findUrlForJob(jobName, artifactPath) {
_throwIfJobIsUnsuccessful(job);

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

function _throwIfJobIsNull(job) {
Expand All @@ -168,6 +171,17 @@ async function artifactURLForMavenLocal() {
return _findUrlForJob('build_and_publish_npm_package-2', 'maven-local.zip');
}

async function artifactURLForReactNative() {
let shortCommit = exec('git rev-parse HEAD', {silent: true})
.toString()
.trim()
.slice(0, 9);
return _findUrlForJob(
'build_npm_package',
`react-native-1000.0.0-${shortCommit}.tgz`,
);
}

async function artifactURLForHermesRNTesterAPK(emulatorArch) {
return _findUrlForJob(
'test_android',
Expand All @@ -194,5 +208,6 @@ module.exports = {
artifactURLForHermesRNTesterAPK,
artifactURLForMavenLocal,
artifactURLHermesDebug,
artifactURLForReactNative,
baseTmpPath,
};
79 changes: 37 additions & 42 deletions scripts/test-e2e-local.js
Expand Up @@ -20,7 +20,6 @@ const {exec, pushd, popd, pwd, cd} = require('shelljs');
const updateTemplatePackage = require('./update-template-package');
const yargs = require('yargs');
const path = require('path');
const fs = require('fs');

const {
checkPackagerRunning,
Expand Down Expand Up @@ -184,20 +183,16 @@ async function testRNTestProject(circleCIArtifacts) {
// create the local npm package to feed the CLI

// base setup required (specular to publish-npm.js)
const baseVersion = require('../packages/react-native/package.json').version;

// in local testing, 1000.0.0 mean we are on main, every other case means we are
// working on a release version
const buildType = baseVersion !== '1000.0.0' ? 'release' : 'dry-run';
const shortCommit = exec('git rev-parse HEAD', {silent: true})
.toString()
.trim()
.slice(0, 9);

// we need to add the unique timestamp to avoid npm/yarn to use some local caches
const dateIdentifier = new Date()
.toISOString()
.slice(0, -8)
.replace(/[-:]/g, '')
.replace(/[T]/g, '-');

const releaseVersion = `${baseVersion}-${dateIdentifier}`;
const releaseVersion = `1000.0.0-${shortCommit}`;
const buildType = 'dry-run';

// Prepare some variables for later use
const repoRoot = pwd();
Expand All @@ -206,8 +201,9 @@ async function testRNTestProject(circleCIArtifacts) {

const mavenLocalPath =
circleCIArtifacts != null
? path.join(circleCIArtifacts.baseTmpPath(), 'maven-local.zip')
? path.join(circleCIArtifacts.baseTmpPath(), 'maven-local')
: '/private/tmp/maven-local';

const hermesPath = await prepareArtifacts(
circleCIArtifacts,
mavenLocalPath,
Expand All @@ -218,52 +214,51 @@ async function testRNTestProject(circleCIArtifacts) {
);

updateTemplatePackage({
'react-native': `file:${localNodeTGZPath}`,
'react-native': `file://${localNodeTGZPath}`,
});

// create locally the node module
exec('npm pack --pack-destination ', {cwd: reactNativePackagePath});

// node pack does not creates a version of React Native with the right name on main.
// Let's add some defensive programming checks:
if (!fs.existsSync(localNodeTGZPath)) {
const tarfile = fs
.readdirSync(reactNativePackagePath)
.find(name => name.startsWith('react-native-') && name.endsWith('.tgz'));
if (!tarfile) {
throw new Error("Couldn't find a zipped version of react-native");
}
exec(
`cp ${path.join(reactNativePackagePath, tarfile)} ${localNodeTGZPath}`,
);
}

pushd('/tmp/');
// need to avoid the pod install step - we'll do it later
exec(
`node ${reactNativePackagePath}/cli.js init RNTestProject --template ${localNodeTGZPath} --skip-install`,
`node ${reactNativePackagePath}/cli.js init RNTestProject --template ${reactNativePackagePath} --skip-install`,
);

cd('RNTestProject');
exec('yarn install');

// When using CircleCI artifacts, the CI will zip maven local into a
// /tmp/maven-local subfolder struct.
// When we generate the project manually, there is no such structure.
const expandedMavenLocal =
circleCIArtifacts == null
? mavenLocalPath
: `${mavenLocalPath}/tmp/maven-local`;
// need to do this here so that Android will be properly setup either way
exec(
`echo "REACT_NATIVE_MAVEN_LOCAL_REPO=${mavenLocalPath}" >> android/gradle.properties`,
`echo "REACT_NATIVE_MAVEN_LOCAL_REPO=${expandedMavenLocal}" >> android/gradle.properties`,
);

// doing the pod install here so that it's easier to play around RNTestProject
cd('ios');
exec('bundle install');
exec(
`HERMES_ENGINE_TARBALL_PATH=${hermesPath} USE_HERMES=${
argv.hermes ? 1 : 0
} bundle exec pod install --ansi`,
);

cd('..');
// Update gradle properties to set Hermes as false
if (!argv.hermes) {
sed(
'-i',
'hermesEnabled=true',
'hermesEnabled=false',
'android/gradle.properties',
);
}

if (argv.platform === 'iOS') {
// doing the pod install here so that it's easier to play around RNTestProject
cd('ios');
exec('bundle install');
exec(
`HERMES_ENGINE_TARBALL_PATH=${hermesPath} USE_HERMES=${
argv.hermes ? 1 : 0
} bundle exec pod install --ansi`,
);

cd('..');
exec('yarn ios');
} else {
// android
Expand Down
9 changes: 7 additions & 2 deletions scripts/testing-utils.js
Expand Up @@ -170,16 +170,21 @@ async function downloadArtifactsFromCircleCI(
) {
const mavenLocalURL = await circleCIArtifacts.artifactURLForMavenLocal();
const hermesURL = await circleCIArtifacts.artifactURLHermesDebug();
const reactNativeURL = await circleCIArtifacts.artifactURLForReactNative();

const hermesPath = path.join(
circleCIArtifacts.baseTmpPath(),
'hermes-ios-debug.tar.gz',
);

console.info('[Download] Maven Local Artifacts');
circleCIArtifacts.downloadArtifact(mavenLocalURL, mavenLocalPath);
console.info(`[Download] Maven Local Artifacts from ${mavenLocalURL}`);
const mavenLocalZipPath = `${mavenLocalPath}.zip`;
circleCIArtifacts.downloadArtifact(mavenLocalURL, mavenLocalZipPath);
exec(`unzip -oq ${mavenLocalZipPath} -d ${mavenLocalPath}`);
console.info('[Download] Hermes');
circleCIArtifacts.downloadArtifact(hermesURL, hermesPath);
console.info(`[Download] React Native from ${reactNativeURL}`);
circleCIArtifacts.downloadArtifact(reactNativeURL, localNodeTGZPath);

return hermesPath;
}
Expand Down