From 65251b8df656fd08be2db59c59e7e1a9b897ca3e Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 28 May 2019 18:37:49 -0700 Subject: [PATCH] Parallelize the build script Uses CircleCI's `parallelism` config option to spin up multiple build processes. --- .circleci/config.yml | 7 ++++-- scripts/rollup/build.js | 48 ++++++++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0056e61642623..6a272c11ab4a2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -118,6 +118,7 @@ jobs: build: docker: *docker environment: *environment + parallelism: 10 steps: - checkout - *restore_yarn_cache @@ -125,8 +126,6 @@ jobs: - run: ./scripts/circleci/add_build_info_json.sh - run: ./scripts/circleci/update_package_versions.sh - run: yarn build - - store_artifacts: - path: ./scripts/error-codes/codes.json - persist_to_workspace: root: build paths: @@ -153,6 +152,10 @@ jobs: path: ./build.tgz - store_artifacts: path: ./build/bundle-sizes.json + - store_artifacts: + # TODO: Update release script to use local file instead of pulling + # from artifacts. + path: ./scripts/error-codes/codes.json lint_build: docker: *docker diff --git a/scripts/rollup/build.js b/scripts/rollup/build.js index 57d3033778895..9feec644bb2e7 100644 --- a/scripts/rollup/build.js +++ b/scripts/rollup/build.js @@ -634,27 +634,41 @@ function handleRollupError(error) { } async function buildEverything() { - await asyncRimRaf('build'); - // Run them serially for better console output // and to avoid any potential race conditions. + + let bundles = []; // eslint-disable-next-line no-for-of-loops/no-for-of-loops for (const bundle of Bundles.bundles) { - await createBundle(bundle, UMD_DEV); - await createBundle(bundle, UMD_PROD); - await createBundle(bundle, UMD_PROFILING); - await createBundle(bundle, NODE_DEV); - await createBundle(bundle, NODE_PROD); - await createBundle(bundle, NODE_PROFILING); - await createBundle(bundle, FB_WWW_DEV); - await createBundle(bundle, FB_WWW_PROD); - await createBundle(bundle, FB_WWW_PROFILING); - await createBundle(bundle, RN_OSS_DEV); - await createBundle(bundle, RN_OSS_PROD); - await createBundle(bundle, RN_OSS_PROFILING); - await createBundle(bundle, RN_FB_DEV); - await createBundle(bundle, RN_FB_PROD); - await createBundle(bundle, RN_FB_PROFILING); + bundles.push( + [bundle, UMD_DEV], + [bundle, UMD_PROD], + [bundle, UMD_PROFILING], + [bundle, NODE_DEV], + [bundle, NODE_PROD], + [bundle, NODE_PROFILING], + [bundle, FB_WWW_DEV], + [bundle, FB_WWW_PROD], + [bundle, FB_WWW_PROFILING], + [bundle, RN_OSS_DEV], + [bundle, RN_OSS_PROD], + [bundle, RN_OSS_PROFILING], + [bundle, RN_FB_DEV], + [bundle, RN_FB_PROD], + [bundle, RN_FB_PROFILING] + ); + } + + if (!shouldExtractErrors && process.env.CIRCLE_NODE_TOTAL) { + // In CI, parallelize bundles across multiple tasks. + const nodeTotal = parseInt(process.env.CIRCLE_NODE_TOTAL, 10); + const nodeIndex = parseInt(process.env.CIRCLE_NODE_INDEX, 10); + bundles = bundles.filter((_, i) => i % nodeTotal === nodeIndex); + } + + // eslint-disable-next-line no-for-of-loops/no-for-of-loops + for (const [bundle, bundleType] of bundles) { + await createBundle(bundle, bundleType); } await Packaging.copyAllShims();