diff --git a/.circleci/config.yml b/.circleci/config.yml index 4b79060d74be..a04959f52c81 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ aliases: - image: circleci/node:10 jobs: - build: + install: <<: *defaults steps: - checkout @@ -21,9 +21,6 @@ jobs: - run: name: Check that yarn.lock is not corrupted command: yarn repo-dirty-check - - run: - name: Bootstrap - command: yarn bootstrap --core - save_cache: name: Cache core dependencies key: core-dependencies-v4-{{ checksum "yarn.lock" }} @@ -40,6 +37,23 @@ jobs: - dev-kits - app - lib + build: + <<: *defaults + steps: + - checkout + - attach_workspace: + at: . + - run: + name: Bootstrap + command: yarn bootstrap --core + - persist_to_workspace: + root: . + paths: + - examples + - addons + - dev-kits + - app + - lib chromatic: <<: *defaults steps: @@ -111,7 +125,7 @@ jobs: yarn packtracker examples: <<: *defaults - parallelism: 4 + parallelism: 10 steps: - checkout - attach_workspace: @@ -292,7 +306,10 @@ jobs: workflows: test: jobs: - - build + - install + - build: + requires: + - install - lint: requires: - build diff --git a/scripts/build-storybooks.js b/scripts/build-storybooks.js index c266587d9e64..fb6693c8016b 100755 --- a/scripts/build-storybooks.js +++ b/scripts/build-storybooks.js @@ -35,6 +35,19 @@ const exec = async (command, args = [], options = {}) => }); }); +const getDeployables = files => { + return files.filter(f => { + const packageJsonLocation = p(['examples', f, 'package.json']); + let stats = null; + try { + stats = statSync(packageJsonLocation); + } catch (e) { + // the folder had no package.json, we'll ignore + } + return stats && stats.isFile() && hasBuildScript(packageJsonLocation); + }); +}; + const hasBuildScript = l => { const text = readFileSync(l, 'utf8'); const json = JSON.parse(text); @@ -116,19 +129,7 @@ const createContent = deployables => { `; }; -const handleExamples = async files => { - const deployables = files.filter(f => { - const packageJsonLocation = p(['examples', f, 'package.json']); - let stats = null; - try { - stats = statSync(packageJsonLocation); - } catch (e) { - // the folder had no package.json, we'll ignore - } - - return stats && stats.isFile() && hasBuildScript(packageJsonLocation); - }); - +const handleExamples = async deployables => { await deployables.reduce(async (acc, d) => { await acc; @@ -150,21 +151,9 @@ const handleExamples = async files => { await exec(`yarn`, [`build-storybook`, `--output-dir=${out}`, '--quiet'], { cwd }); logger.log('-------'); - logger.log('✅ done'); + logger.log(`✅ ${d} built`); logger.log('-------'); }, Promise.resolve()); - - logger.log(''); - logger.log(`📑 creating index`); - - const indexLocation = p(['built-storybooks', 'index.html']); - const indexContent = createContent(deployables); - - await writeFile(indexLocation, indexContent); - - logger.log('-------'); - logger.log('✅ done'); - logger.log('-------'); }; const run = async () => { @@ -176,8 +165,29 @@ const run = async () => { const offset = step * a; const list = examples.slice().splice(offset, step); + const deployables = getDeployables(list); + + if (deployables.length) { + logger.log(`will build: ${deployables.join(', ')}`); + await handleExamples(deployables); + } + + if ( + deployables.length && + (process.env.CIRCLE_NODE_INDEX === undefined || + process.env.CIRCLE_NODE_INDEX === '0' || + process.env.CIRCLE_NODE_INDEX === 0) + ) { + const indexLocation = p(['built-storybooks', 'index.html']); + logger.log(''); + logger.log(`📑 creating index at: ${indexLocation}`); + logger.log(''); + await writeFile(indexLocation, createContent(deployables)); - await handleExamples(list); + logger.log('-------'); + logger.log('✅ done'); + logger.log('-------'); + } }; run().catch(e => {