Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech/change parallelism #10041

Merged
merged 8 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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