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

CLI: Fix sb init in Yarn workspace environment #10985

Merged
merged 4 commits into from
Jun 1, 2020

Conversation

gaetanmaisse
Copy link
Member

@gaetanmaisse gaetanmaisse commented May 29, 2020

Issue: #10915

What I did

  • Add --ignore-workspace-root-check flag when CLI is running yarn add command.
  • Add E2E test for Yarn workspace. It's based on a simple React setup.
  • Remove skip-install option from sb init command used in E2E because it can hide some issues with the dependency installation process of @storybook/cli. For instance, missing Yarn flags needed to have the CLI working in Yarn workspaces.

--

Also, improve jobs assignment on CI nodes:

With the current algorithm, some nodes have no jobs assigned to them due to rounding consideration. For instance, with 10 nodes and 13 jobs to assign:

  • 13 jobs / 10 nodes -> 1.3 jobs per node -> rounded to 2 -> only the 1st 6 nodes run 2 jobs, the 7th 1 job and the other 0 job.

Using a modulo ensures that each node will at least run 1 job and thus reduce the E2E run duration (in theory 🤞).

How to test

  • E2E tests should be 🟢 on CI, especially new E2E test run in example-v2 job

version: 'latest',
generator: [
'cd {{name}}-v{{version}}',
'echo "{ \\"name\\": \\"workspace-root\\", \\"private\\": true, \\"workspaces\\": [] }" > package.json',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Init a Yarn workspace with the most simple way (i.e. without any tricks or new dependency)

@gaetanmaisse gaetanmaisse force-pushed the fix-10915-cli-init-in-yarn-workspace branch 3 times, most recently from a388860 to ef9e891 Compare May 29, 2020 17:04
Add `--ignore-workspace-root-check` to avoid Yarn error when adding dependencies to the workspace root.
@gaetanmaisse gaetanmaisse force-pushed the fix-10915-cli-init-in-yarn-workspace branch from 9a9a796 to d0ef50a Compare May 29, 2020 18:45
@gaetanmaisse gaetanmaisse linked an issue May 29, 2020 that may be closed by this pull request
Removed this option because it can hide some issues with dependency installation process of @storybook/cli.
For instance, missing Yarn flags needed to have the CLI working in Yarn workspaces.

Also, as `sb init` is now running `yarn/npm install` the resolution step has to be made before init Storybook.
@gaetanmaisse gaetanmaisse force-pushed the fix-10915-cli-init-in-yarn-workspace branch from d0ef50a to 82e418f Compare May 29, 2020 18:47
With the previous algorithm, some nodes have no jobs assigned to them due to rounding consideration.
For example with 10 nodes and 13 jobs to assign:
 13 jobs / 10 nodes -> 1.3 jobs per node -> rounded to 2 -> only the 1st 6 nodes run 2 jobs, the 7th 1 job and the other 0 job.

Using a modulo ensures that each node will at least run 1 job.
@gaetanmaisse gaetanmaisse force-pushed the fix-10915-cli-init-in-yarn-workspace branch from a39832b to 2345957 Compare May 29, 2020 18:49
@gaetanmaisse gaetanmaisse marked this pull request as ready for review May 29, 2020 19:15
const nodeIndex = +process.env.CIRCLE_NODE_INDEX || 0;
const numberOfNodes = +process.env.CIRCLE_NODE_TOTAL || 1;

const list = narrowedConfigs.filter((_, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to do that for a while now ^^
This logic is shared in other runners, chromatic and examples if I'm right

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shilman shilman merged commit c9fb748 into next Jun 1, 2020
@shilman shilman deleted the fix-10915-cli-init-in-yarn-workspace branch June 1, 2020 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

automatic initialization fails in projects using yarn workspaces
3 participants