mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
c540ff7bd1
Summary: This PR is a follow up of https://github.com/facebook/react-native/pull/35075 and https://github.com/facebook/react-native/commit/1546666a6d713ef756b2f11de9581e3b2bbe08dc to ensure that even in the local e2e testing scenario the new maven approach is followed - without this, RNTestProject on Android won't work, like so: <img width="1905" alt="Screenshot 2022-10-27 at 12 15 38" src="https://user-images.githubusercontent.com/16104054/198334105-30fb2037-4e7c-4814-8c3f-2412ba0bd49f.png"> And iOS will always build everything from source every time. This PR addresses both by generating the artifacts locally, and passing them to RNTestProject as if they were coming from a url (mimicking as closely as possible the behaviour for the final user) In doing so, there's been some refactoring to prep the ground for follow up work. * refactor CI to rely less on scripts directly in the CircleCI config, but invoke .js ones * we should be able to trigger more the "manual" artifacts generation so that it will only happen once between RNTester and RNTestProject, and we can pass existing artifacts to the other flows. * once all of this in place, a very good improvement would be to be able to download the maven artifacts kind of like nightlies and stables do. This will only be viable by checking that there's no local changes, after which there needs to be logic to pull down from CircleCI the artifacts based on git commit <-> circleCI job references. --- While at it, I've also fixed the hermes-engine podspec logic for detecting if it's on CI: basically the local e2e script needs to align with the changes done here: https://github.com/facebook/react-native/commit/4b512077354eb4702ce144e9958d7513c1607275 but as you can see there, the condition was actually inconsistent across the various files, so realigned to `CI === 'true'`. We probably didn't catch that so far 'cause the other condition in the hermes podspect (existence of `hermestag_file`) is only true on release branches and this new logic has not been in any release branches yet. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [Internal] [Fixed] - add logic to local e2e script to handle maven local for iOS and Android accordingly Pull Request resolved: https://github.com/facebook/react-native/pull/35104 Test Plan: Run ` yarn test-e2e-local -t RNTestProject -p Android` successfully. Run ` yarn test-e2e-local -t RNTestProject -p iOS` successfully. On the pod install stage, you will see `[Hermes] Using pre-built Hermes binaries from local path.` Reviewed By: dmytrorykun Differential Revision: D40893239 Pulled By: cipolleschi fbshipit-source-id: a31217ec4f177383c62292d00fabc4cbe4391cfd
141 lines
4.0 KiB
JavaScript
141 lines
4.0 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const {exec, echo, exit, test, env, pushd, popd} = require('shelljs');
|
|
const {saveFiles} = require('./scm-utils');
|
|
const {createHermesPrebuiltArtifactsTarball} = require('./hermes/hermes-utils');
|
|
|
|
// TODO: we should probably remove this because of this? https://github.com/facebook/react-native/pull/34846
|
|
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
|
|
echo('Generating Android artifacts inside /tmp/maven-local');
|
|
if (exec('./gradlew publishAllToMavenTempLocal').code) {
|
|
echo('Could not generate artifacts');
|
|
exit(1);
|
|
}
|
|
|
|
echo('Generated artifacts for Maven');
|
|
|
|
let artifacts = [
|
|
'.module',
|
|
'.pom',
|
|
'-debug.aar',
|
|
'-release.aar',
|
|
'-debug-sources.jar',
|
|
'-release-sources.jar',
|
|
].map(suffix => {
|
|
return `react-native-${releaseVersion}${suffix}`;
|
|
});
|
|
|
|
artifacts.forEach(name => {
|
|
if (
|
|
!test(
|
|
'-e',
|
|
`/tmp/maven-local/com/facebook/react/react-native/${releaseVersion}/${name}`,
|
|
)
|
|
) {
|
|
echo(
|
|
`Failing as expected file: \n\
|
|
/tmp/maven-local/com/facebook/react/react-native/${releaseVersion}/${name}\n\
|
|
was not correctly generated.`,
|
|
);
|
|
exit(1);
|
|
}
|
|
});
|
|
}
|
|
|
|
function publishAndroidArtifactsToMaven(releaseVersion, isNightly) {
|
|
// -------- Publish every artifact to Maven Central
|
|
// The GPG key is base64 encoded on CircleCI
|
|
let buff = Buffer.from(env.ORG_GRADLE_PROJECT_SIGNING_KEY_ENCODED, 'base64');
|
|
env.ORG_GRADLE_PROJECT_SIGNING_KEY = buff.toString('ascii');
|
|
if (exec('./gradlew publishAllToSonatype -PisNightly=' + isNightly).code) {
|
|
echo('Failed to publish artifacts to Sonatype (Maven Central)');
|
|
exit(1);
|
|
}
|
|
|
|
// We want to gate ourselves against accidentally publishing a 1.x or a 1000.x on
|
|
// maven central which will break the semver for our artifacts.
|
|
if (!isNightly && releaseVersion.startsWith('0.')) {
|
|
// -------- For stable releases, we also need to close and release the staging repository.
|
|
if (exec('./gradlew closeAndReleaseSonatypeStagingRepository').code) {
|
|
echo(
|
|
'Failed to close and release the staging repository on Sonatype (Maven Central)',
|
|
);
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
echo('Published artifacts to Maven Central');
|
|
}
|
|
|
|
function generateiOSArtifacts(
|
|
jsiFolder,
|
|
hermesCoreSourceFolder,
|
|
buildType,
|
|
releaseVersion,
|
|
targetFolder,
|
|
) {
|
|
pushd(`${hermesCoreSourceFolder}`);
|
|
|
|
//Need to generate hermesc
|
|
exec(
|
|
`${hermesCoreSourceFolder}/utils/build-hermesc-xcode.sh ${hermesCoreSourceFolder}/build_host_hermesc`,
|
|
);
|
|
|
|
//Generating iOS Artifacts
|
|
exec(
|
|
`JSI_PATH=${jsiFolder} BUILD_TYPE=${buildType} ${hermesCoreSourceFolder}/utils/build-mac-framework.sh`,
|
|
);
|
|
|
|
exec(
|
|
`JSI_PATH=${jsiFolder} BUILD_TYPE=${buildType} ${hermesCoreSourceFolder}/utils/build-ios-framework.sh`,
|
|
);
|
|
|
|
popd();
|
|
|
|
const tarballOutputPath = createHermesPrebuiltArtifactsTarball(
|
|
hermesCoreSourceFolder,
|
|
buildType,
|
|
releaseVersion,
|
|
targetFolder,
|
|
true, // this is excludeDebugSymbols, we keep it as the default
|
|
);
|
|
|
|
return tarballOutputPath;
|
|
}
|
|
|
|
module.exports = {
|
|
generateAndroidArtifacts,
|
|
generateiOSArtifacts,
|
|
publishAndroidArtifactsToMaven,
|
|
saveFilesToRestore,
|
|
};
|