Skip to content

Commit

Permalink
(squashed) last set of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kelset committed Sep 26, 2022
1 parent d0d3f5a commit 95ffd40
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 99 deletions.
23 changes: 5 additions & 18 deletions scripts/publish-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ const {
exitIfNotOnGit,
getCurrentCommit,
isTaggedLatest,
saveFiles,
} = require('./scm-utils');
const {generateAndroidArtifacts} = require('./release-utils');
const {
generateAndroidArtifacts,
saveFilesToRestore,
} = require('./release-utils');
const fs = require('fs');
const os = require('os');
const path = require('path');
Expand Down Expand Up @@ -73,22 +75,7 @@ const dryRunBuild = argv.dryRun;
const includeHermes = argv.includeHermes;
const isCommitly = nightlyBuild || dryRunBuild;

const filesToSaveAndRestore = [
'template/Gemfile',
'template/_ruby-version',
'template/package.json',
'.ruby-version',
'Gemfile.lock',
'Gemfile',
'package.json',
'ReactAndroid/gradle.properties',
'Libraries/Core/ReactNativeVersion.js',
'React/Base/RCTVersion.m',
'ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
'ReactCommon/cxxreact/ReactNativeVersion.h',
];

saveFiles(filesToSaveAndRestore, tmpPublishingFolder);
saveFilesToRestore(tmpPublishingFolder);

if (includeHermes) {
const HERMES_INSTALL_LOCATION = 'sdks';
Expand Down
22 changes: 21 additions & 1 deletion scripts/release-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,26 @@
'use strict';

const {exec, echo, exit, test, env} = require('shelljs');
const {revertFiles} = require('./scm-utils');
const {revertFiles, saveFiles} = require('./scm-utils');

function saveFilesToRestore(tmpPublishingFolder) {
const filesToSaveAndRestore = [
'template/Gemfile',
'template/_ruby-version',
'template/package.json',
'.ruby-version',
'Gemfile.lock',
'Gemfile',
'package.json',
'ReactAndroid/gradle.properties',
'Libraries/Core/ReactNativeVersion.js',
'React/Base/RCTVersion.m',
'ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java',
'ReactCommon/cxxreact/ReactNativeVersion.h',
];

saveFiles(filesToSaveAndRestore, tmpPublishingFolder);
}

function generateAndroidArtifacts(releaseVersion, tmpPublishingFolder) {
// -------- Generating Android Artifacts
Expand Down Expand Up @@ -61,4 +80,5 @@ function generateAndroidArtifacts(releaseVersion, tmpPublishingFolder) {

module.exports = {
generateAndroidArtifacts,
saveFilesToRestore,
};
160 changes: 82 additions & 78 deletions scripts/test-e2e-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@ const os = require('os');
const {
launchAndroidEmulator,
isPackagerRunning,
launchPackagesInSeparateWindow,
launchPackagerInSeparateWindow,
} = require('./testing-utils');

const {generateAndroidArtifacts} = require('./release-utils');

// setting this just 'cause this https://github.com/facebook/react-native/commit/0a3ca80af401654896cbc73e235711eef0f9b3c5
// breaks a bunch of stuff. This should be enough.
// TODO: follow up with Nicola in understanding the impact of the commit, and if we can remove this
// also, remove the folder
process.env.TMP_PUBLISH_DIR = fs.mkdtempSync(
path.join(os.tmpdir(), 'rn-publish-'),
);
console.info(`The temp folder is ${process.env.TMP_PUBLISH_DIR}`);
const {
generateAndroidArtifacts,
saveFilesToRestore,
} = require('./release-utils');

const argv = yargs
.option('t', {
Expand Down Expand Up @@ -72,12 +66,16 @@ if (isPackagerRunning() === 'running') {
}

if (argv.target === 'RNTester') {
//FIXME: make sure that the commands retains colors
// FIXME: make sure that the commands retains colors
// (--ansi) doesn't always work
// see also https://github.com/shelljs/shelljs/issues/86

if (argv.platform === 'iOS') {
console.info("We're going to test the Hermes version of RNTester iOS");
console.info(
`We're going to test the ${
argv.hermes ? 'Hermes' : 'JSC'
} version of RNTester iOS`,
);
exec(
`cd packages/rn-tester && USE_HERMES=${
argv.hermes ? 1 : 0
Expand All @@ -86,7 +84,7 @@ if (argv.target === 'RNTester') {

// if everything succeeded so far, we can launch Metro and the app
// start the Metro server in a separate window
launchPackagesInSeparateWindow();
launchPackagerInSeparateWindow();

// launch the app on iOS simulator
pushd('packages/rn-tester');
Expand All @@ -97,21 +95,24 @@ if (argv.target === 'RNTester') {

launchAndroidEmulator();

if (argv.hermes) {
console.info(
"We're going to test the Hermes version of RNTester Android",
);
exec(
'./gradlew :packages:rn-tester:android:app:installHermesDebug --quiet',
);
} else {
console.info("We're going to test the JSC version of RNTester Android");
exec('./gradlew :packages:rn-tester:android:app:installJscDebug --quiet');
}
console.info(
`We're going to test the ${
argv.hermes ? 'Hermes' : 'JSC'
} version of RNTester Android`,
);
exec(
`./gradlew :packages:rn-tester:android:app:${
argv.hermes ? 'installHermesDebug' : 'installJscDebug'
} --quiet`,
);

// launch the app on Android simulator
// TODO: we should find a way to make it work like for iOS, via npx react-native run-android
// currently, that fails with an error.

// if everything succeeded so far, we can launch Metro and the app
// start the Metro server in a separate window
launchPackagesInSeparateWindow();
launchPackagerInSeparateWindow();
// just to make sure that the Android up won't have troubles finding the Metro server
exec('adb reverse tcp:8081 tcp:8081');
// launch the app
Expand All @@ -124,6 +125,14 @@ if (argv.target === 'RNTester') {

// create the local npm package to feed the CLI

// base setup required (specular to publish-npm.js)
const tmpPublishingFolder = fs.mkdtempSync(
path.join(os.tmpdir(), 'rn-publish-'),
);
console.info(`The temp publishing folder is ${tmpPublishingFolder}`);

saveFilesToRestore(tmpPublishingFolder);

// we need to add the unique timestamp to avoid npm/yarn to use some local caches
const baseVersion = require('../package.json').version;

Expand All @@ -135,67 +144,62 @@ if (argv.target === 'RNTester') {

const releaseVersion = `${baseVersion}-${dateIdentifier}`;

// need to put it into into a try finally to ensure that we clean up the state
try {
// this is needed to generate the Android artifacts correctly
exec(`node scripts/set-rn-version.js --to-version ${releaseVersion}`).code;
// this is needed to generate the Android artifacts correctly
exec(`node scripts/set-rn-version.js --to-version ${releaseVersion}`).code;

// Generate native files (Android only for now)
generateAndroidArtifacts(releaseVersion);
// Generate native files (Android only for now)
generateAndroidArtifacts(releaseVersion, tmpPublishingFolder);

// create locally the node module
exec('npm pack');
// create locally the node module
exec('npm pack');

const localNodeTGZPath = `${pwd()}/react-native-${releaseVersion}.tgz`;
exec(`node scripts/set-rn-template-version.js "file:${localNodeTGZPath}"`);
const localNodeTGZPath = `${pwd()}/react-native-${releaseVersion}.tgz`;
exec(`node scripts/set-rn-template-version.js "file:${localNodeTGZPath}"`);

const repoRoot = pwd();
const repoRoot = pwd();

pushd('/tmp/');
// need to avoid the pod install step because it will fail! (see above)
exec(
`node ${repoRoot}/cli.js init RNTestProject --template ${repoRoot} --skip-install`,
);
pushd('/tmp/');
// need to avoid the pod install step because it will fail! (see above)
exec(
`node ${repoRoot}/cli.js init RNTestProject --template ${repoRoot} --skip-install`,
);

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

if (argv.platform === 'iOS') {
// if we want iOS, we need to do pod install - but with a trick
cd('ios');
exec('bundle install');

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

if (argv.platform === 'iOS') {
// if we want iOS, we need to do pod install - but with a trick
cd('ios');
exec('bundle install');

// TODO: we should be able to also use HERMES_ENGINE_TARBALL_PATH
// if we can make RNTester step generate it already so that it gets reused

// need to discern if it's main branch or release branch
if (baseVersion === '1000.0.0') {
// main branch
exec(
`USE_HERMES=${argv.hermes ? 1 : 0} bundle exec pod install --ansi`,
);
} else {
// a release branch
// copy over the .hermesversion file from react-native core into the RNTestProject
exec(`cp -f ${repoRoot}/sdks/.hermesversion .`);
exec(
`CI=true USE_HERMES=${
argv.hermes ? 1 : 0
} bundle exec pod install --ansi`,
);
}
cd('..');
exec('yarn ios');
// TODO: we should be able to also use HERMES_ENGINE_TARBALL_PATH
// if we can make RNTester step generate it already so that it gets reused

// need to discern if it's main branch or release branch
if (baseVersion === '1000.0.0') {
// main branch
exec(`USE_HERMES=${argv.hermes ? 1 : 0} bundle exec pod install --ansi`);
} else {
// android
exec('yarn android');
// TODO: to test this, I need to apply changes on top of a release branch
// a release branch
// copy over the .hermesversion file from react-native core into the RNTestProject
exec(`cp -f ${repoRoot}/sdks/.hermesversion .`);
exec(
`CI=true USE_HERMES=${
argv.hermes ? 1 : 0
} bundle exec pod install --ansi`,
);
}
popd();
} finally {
// at the end here I most likely want to set back the rn version to baseVersion!
// for git "cleanness" reasons
exec(`node scripts/set-rn-template-version.js ${baseVersion}`);
cd('..');
exec('yarn ios');
} else {
// android
exec('yarn android');
}
popd();

// just cleaning up the temp folder, the rest is done by the test clean script
exec(`rm -rf ${tmpPublishingFolder}`);
}

exit(0);
4 changes: 2 additions & 2 deletions scripts/testing-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ function isPackagerRunning(
// literally, this is macos only
// a more robust implementation can be found here:
// https://github.com/react-native-community/cli/blob/7c003f2b1d9d80ec5c167614ba533a004272c685/packages/cli-platform-android/src/commands/runAndroid/index.ts#L195
function launchPackagesInSeparateWindow() {
function launchPackagerInSeparateWindow() {
exec("open -a 'Terminal' ./scripts/packager.sh");
}

module.exports = {
launchAndroidEmulator,
isPackagerRunning,
launchPackagesInSeparateWindow,
launchPackagerInSeparateWindow,
};

0 comments on commit 95ffd40

Please sign in to comment.