From a2d6f5afe57ec6d4575051a4e5ae275e6ebd67da Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 20 Jul 2022 12:40:59 +0100 Subject: [PATCH] fix: build hermes from source on PR against stable --- .circleci/config.yml | 15 +++------------ scripts/hermes/hermes-utils.js | 17 ++++++++++++++++- scripts/hermes/prepare-hermes-for-build.js | 8 +++++--- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d3710bc9cd891..cf7fb4912c52d3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -936,18 +936,9 @@ jobs: - run: name: Download Hermes tarball command: | - node scripts/hermes/prepare-hermes-for-build - - # If Hermes is not built from source, we don't have these folders. - DOWNLOAD_FOLDER=sdks/download/ - if [[ -d $DOWNLOAD_FOLDER ]]; then - cp $DOWNLOAD_FOLDER* $HERMES_WS_DIR/download/. - fi - - HERMES_FOLDER=sdks/hermes/ - if [[ -d $HERMES_FOLDER ]]; then - cp -r $HERMES_FOLDER* $HERMES_WS_DIR/hermes/. - fi + 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: key: v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }} paths: diff --git a/scripts/hermes/hermes-utils.js b/scripts/hermes/hermes-utils.js index 79b4d74f7bb605..711e463dad88f6 100644 --- a/scripts/hermes/hermes-utils.js +++ b/scripts/hermes/hermes-utils.js @@ -190,12 +190,27 @@ function isOnAReleaseTag() { return currentRemote.endsWith('facebook/react-native.git'); } -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) { const hermesTag = readHermesTag(); return ( isOnAReleaseBranch() || isOnAReleaseTag() || + isPRAgainstStable(pullRequest) || hermesTag === DEFAULT_HERMES_TAG ); } 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); });