Skip to content

Commit

Permalink
Merge pull request #10041 from storybookjs/tech/change-parallelism
Browse files Browse the repository at this point in the history
Tech/change parallelism
  • Loading branch information
ndelangen committed Mar 3, 2020
2 parents 2b6039f + 4b45e5d commit 26c7e5b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 33 deletions.
29 changes: 23 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ aliases:
- image: circleci/node:10

jobs:
build:
install:
<<: *defaults
steps:
- checkout
Expand All @@ -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" }}
Expand All @@ -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:
Expand Down Expand Up @@ -111,7 +125,7 @@ jobs:
yarn packtracker
examples:
<<: *defaults
parallelism: 4
parallelism: 10
steps:
- checkout
- attach_workspace:
Expand Down Expand Up @@ -292,7 +306,10 @@ jobs:
workflows:
test:
jobs:
- build
- install
- build:
requires:
- install
- lint:
requires:
- build
Expand Down
64 changes: 37 additions & 27 deletions scripts/build-storybooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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 () => {
Expand All @@ -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 => {
Expand Down

0 comments on commit 26c7e5b

Please sign in to comment.