From 361d939afd0b43b2e9e6ea0d4c619482e91e82e3 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 20 Jul 2022 08:53:38 -0700 Subject: [PATCH] Build Hermes in CI also when it is against stable branch (#34224) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34224 This Diff is a copy of this [PR](https://github.com/facebook/react-native/pull/34228) that we have against 0.69-stable. This Diff makes sure we can build Hermes also in PR that are created against a stable branch ## Changelog [General] [Changed] - Make sure we can build Hermes from source when PR are opened agains -stable Reviewed By: cortinico Differential Revision: D37961092 fbshipit-source-id: 65577fcc69f0e2a68377cbd46e3bd3a6af24e7c3 --- .circleci/config.yml | 2 +- scripts/hermes/hermes-utils.js | 17 ++++++++++++++++- scripts/hermes/prepare-hermes-for-build.js | 8 +++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fee64be10324af..7d3f39b95653a2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -898,7 +898,7 @@ jobs: - run: name: Download Hermes tarball command: | - node scripts/hermes/prepare-hermes-for-build + node scripts/hermes/prepare-hermes-for-build $CIRCLE_PULL_REQUEST cp sdks/download/* $HERMES_WS_DIR/download/. cp -r sdks/hermes/* $HERMES_WS_DIR/hermes/. - save_cache: diff --git a/scripts/hermes/hermes-utils.js b/scripts/hermes/hermes-utils.js index 588c11c52e97ba..1dc2bba067d6c8 100644 --- a/scripts/hermes/hermes-utils.js +++ b/scripts/hermes/hermes-utils.js @@ -199,11 +199,26 @@ function isRequestingLatestCommitFromHermesMainBranch() { return hermesTag === DEFAULT_HERMES_TAG; } -function shouldBuildHermesFromSource() { +function isPRAgainstStable(pullRequest) { + if (pullRequest == null) { + return false; + } + + const prComponents = pullRequest.split('/'); + const prNumber = prComponents[prComponents.length - 1]; + const apiURL = `https://api.github.com/repos/facebook/react-native/pulls/${prNumber}`; + const prJson = JSON.parse(execSync(`curl ${apiURL}`).toString()); + const baseBranch = prJson.base.label; + + return baseBranch.endsWith('-stable'); +} + +function shouldBuildHermesFromSource(pullRequest) { return ( !isTestingAgainstLocalHermesTarball() && (isOnAReactNativeReleaseBranch() || isOnAReactNativeReleaseTag() || + isPRAgainstStable(pullRequest) || isRequestingLatestCommitFromHermesMainBranch()) ); } diff --git a/scripts/hermes/prepare-hermes-for-build.js b/scripts/hermes/prepare-hermes-for-build.js index 29a5d9ae27ad2b..42b33bad58a0dc 100644 --- a/scripts/hermes/prepare-hermes-for-build.js +++ b/scripts/hermes/prepare-hermes-for-build.js @@ -23,8 +23,8 @@ const { shouldBuildHermesFromSource, } = require('./hermes-utils'); -async function main() { - if (!shouldBuildHermesFromSource()) { +async function main(pullRequest) { + if (!shouldBuildHermesFromSource(pullRequest)) { copyPodSpec(); return; } @@ -40,6 +40,8 @@ async function main() { } } -main().then(() => { +const pullRequest = process.argv.length > 2 ? process.argv[2] : null; +console.log(`Pull request detected: ${pullRequest}`); +main(pullRequest).then(() => { process.exit(0); });