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

Build: Fix benchmark to run on local packages #19832

Merged
merged 6 commits into from
Nov 15, 2022
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
48 changes: 24 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ commands:
then
export HOME=$(getent passwd $(id -un) | cut -d: -f6)
fi

# known_hosts
mkdir -p ~/.ssh
if [ -x "$(command -v ssh-keyscan)" ] && ([ "<< parameters.keyscan_github >>" == "true" ] || [ "<< parameters.keyscan_bitbucket >>" == "true" ])
Expand All @@ -126,19 +126,19 @@ commands:
echo 'bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==
' >> ~/.ssh/known_hosts
fi

(umask 077; touch ~/.ssh/id_rsa)
chmod 0600 ~/.ssh/id_rsa
(echo $CHECKOUT_KEY > ~/.ssh/id_rsa)

# use git+ssh instead of https
git config --global url."ssh://[email protected]".insteadOf "https://github.com" || true
git config --global gc.auto 0 || true

# checkout
git clone << parameters.clone_options >> $CIRCLE_REPOSITORY_URL "<< parameters.path >>"
cd "<< parameters.path >>"

# Fetch remote and check the commit ID of the checked out code
if [ -n "$CIRCLE_TAG" ]
then
Expand All @@ -152,7 +152,7 @@ commands:
# others
git fetch << parameters.fetch_options >> --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH"
fi

# Check the commit ID of the checked out code
if [ -n "$CIRCLE_TAG" ]
then
Expand All @@ -163,7 +163,7 @@ commands:
git reset --hard "$CIRCLE_SHA1"
git checkout -q -B "$CIRCLE_BRANCH"
fi

git reset --hard "$CIRCLE_SHA1"
name: Checkout code shallow
cancel-workflow-on-failure:
Expand Down Expand Up @@ -266,21 +266,21 @@ jobs:
name: set up cra repro, skip tests
command: |
cd code
node ./lib/cli/bin/index.js repro-next cra/default-js --output ../../cra-bench
SANDBOX_ROOT=../bench yarn task --task sandbox --template cra/default-ts --skip-template-stories --start-from=never --no-link
- run:
name: Run @storybook/bench on repro
command: |
cd ../cra-bench
cd bench/cra-default-ts
rm -rf node_modules
mkdir node_modules
npx -p @storybook/bench@next sb-bench 'yarn install' --label cra
- run:
name: prep artifacts
when: always
command: tar cvzf /tmp/sb-bench.tar.gz ../cra-bench
command: tar cvzf /tmp/cra-default-ts-bench.tar.gz bench/cra-default-ts
- store_artifacts:
path: /tmp/sb-bench.tar.gz
destination: sb-bench.tar.gz
path: /tmp/cra-default-ts-bench.tar.gz
destination: cra-default-ts-bench.tar.gz
react-vite-bench:
executor:
class: large
Expand All @@ -306,21 +306,21 @@ jobs:
name: set up react-vite repro, skip tests
command: |
cd code
node ./lib/cli/bin/index.js repro-next react-vite/default-ts --output ../../react-vite-bench
SANDBOX_ROOT=../bench yarn task --task sandbox --template react-vite/default-ts --skip-template-stories --start-from=never --no-link
- run:
name: Run @storybook/bench on repro
command: |
cd ../react-vite-bench
cd bench/react-vite-default-ts
rm -rf node_modules
mkdir node_modules
npx -p @storybook/bench@next sb-bench 'yarn install' --label react-vite
npx -p @storybook/bench@next sb-bench 'yarn install' --no-start --label react-vite
- run:
name: prep artifacts
when: always
command: tar cvzf /tmp/sb-bench.tar.gz ../react-vite-bench
command: tar cvzf /tmp/react-vite-default-ts-bench.tar.gz bench/react-vite-default-ts
- store_artifacts:
path: /tmp/sb-bench.tar.gz
destination: sb-bench.tar.gz
path: /tmp/react-vite-default-ts-bench.tar.gz
destination: react-vite-default-ts-bench.tar.gz
lint:
executor:
class: medium
Expand Down Expand Up @@ -558,8 +558,8 @@ workflows:
ci:
when:
and:
- equal: [ api, << pipeline.trigger_source >> ]
- equal: [ ci, << pipeline.parameters.workflow >> ]
- equal: [api, << pipeline.trigger_source >>]
- equal: [ci, << pipeline.parameters.workflow >>]
jobs:
- build
- lint:
Expand Down Expand Up @@ -591,7 +591,7 @@ workflows:
- build-sandboxes
pr:
when:
equal: [ pr, << pipeline.parameters.workflow >> ]
equal: [pr, << pipeline.parameters.workflow >>]
jobs:
- build
- lint:
Expand Down Expand Up @@ -640,7 +640,7 @@ workflows:
- build-sandboxes
merged:
when:
equal: [ merged, << pipeline.parameters.workflow >> ]
equal: [merged, << pipeline.parameters.workflow >>]
jobs:
- build
- lint:
Expand Down Expand Up @@ -689,7 +689,7 @@ workflows:
- build-sandboxes
daily:
when:
equal: [ daily, << pipeline.parameters.workflow >> ]
equal: [daily, << pipeline.parameters.workflow >>]
jobs:
- build
- create-sandboxes:
Expand All @@ -714,4 +714,4 @@ workflows:
- e2e-sandboxes:
parallelism: 24
requires:
- build-sandboxes
- build-sandboxes
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ junit.xml
test-results
/repros
/sandbox
/bench
.verdaccio-cache

# Yarn stuff
Expand Down
2 changes: 1 addition & 1 deletion scripts/get-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pathExists } from 'fs-extra';
import { resolve } from 'path';
import { allTemplates, templatesByCadence } from '../code/lib/cli/src/repro-templates';

const sandboxDir = resolve(__dirname, '../sandbox');
const sandboxDir = process.env.SANDBOX_ROOT || resolve(__dirname, '../sandbox');

export type Cadence = keyof typeof templatesByCadence;
export type Template = {
Expand Down
7 changes: 6 additions & 1 deletion scripts/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { e2eTests } from './tasks/e2e-tests';

import { allTemplates as TEMPLATES } from '../code/lib/cli/src/repro-templates';

const sandboxDir = resolve(__dirname, '../sandbox');
const sandboxDir = process.env.SANDBOX_ROOT || resolve(__dirname, '../sandbox');
const codeDir = resolve(__dirname, '../code');
const junitDir = resolve(__dirname, '../test-results');

Expand Down Expand Up @@ -163,6 +163,11 @@ export const options = createOptions({
description: 'Store results in junit format?',
promptType: false,
},
skipTemplateStories: {
type: 'boolean',
description: 'Do not include template stories and their addons',
promptType: false,
},
});

type PassedOptionValues = Omit<OptionValues<typeof options>, 'task' | 'startFrom' | 'junit'>;
Expand Down
26 changes: 10 additions & 16 deletions scripts/tasks/sandbox-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const essentialsAddons = [

export const create: Task['run'] = async (
{ key, template, sandboxDir },
{ addon: addons, fromLocalRepro, dryRun, debug }
{ addon: addons, fromLocalRepro, dryRun, debug, skipTemplateStories }
) => {
const parentDir = resolve(sandboxDir, '..');
await ensureDir(parentDir);
Expand Down Expand Up @@ -70,9 +70,11 @@ export const create: Task['run'] = async (
}

const cwd = sandboxDir;
for (const addon of addons) {
const addonName = `@storybook/addon-${addon}`;
await executeCLIStep(steps.add, { argument: addonName, cwd, dryRun, debug });
if (!skipTemplateStories) {
for (const addon of addons) {
const addonName = `@storybook/addon-${addon}`;
await executeCLIStep(steps.add, { argument: addonName, cwd, dryRun, debug });
}
}

const mainConfig = await readMainConfig({ cwd });
Expand Down Expand Up @@ -231,8 +233,6 @@ function setSandboxViteFinal(mainConfig: ConfigFile) {
);
}



// Update the stories field to ensure that no TS files
// that are linked from the renderer are picked up in non-TS projects
function updateStoriesField(mainConfig: ConfigFile, isJs: boolean) {
Expand All @@ -244,7 +244,6 @@ function updateStoriesField(mainConfig: ConfigFile, isJs: boolean) {
? stories.map((specifier) => specifier.replace('js|jsx|ts|tsx', 'js|jsx'))
: stories;


mainConfig.setFieldValue(['stories'], [...updatedStories]);
}

Expand All @@ -257,7 +256,7 @@ function addStoriesEntry(mainConfig: ConfigFile, path: string) {
titlePrefix: path,
files: '**/*.@(mdx|stories.@(js|jsx|ts|tsx))',
};

mainConfig.setFieldValue(['stories'], [...stories, entry]);
}

Expand All @@ -278,7 +277,7 @@ async function linkPackageStories(
: resolve(cwd, 'template-stories', packageDir);
await ensureSymlink(source, target);

if (!linkInDir) addStoriesEntry(mainConfig, packageDir)
if (!linkInDir) addStoriesEntry(mainConfig, packageDir);

// Add `previewAnnotation` entries of the form
// './template-stories/lib/store/preview.[tj]s'
Expand Down Expand Up @@ -320,7 +319,6 @@ function addExtraDependencies({
}
}


export const addStories: Task['run'] = async (
{ sandboxDir, template },
{ addon: extraAddons, dryRun, debug }
Expand All @@ -332,11 +330,7 @@ export const addStories: Task['run'] = async (

// Ensure that we match the right stories in the stories directory
const packageJson = await import(join(cwd, 'package.json'));
updateStoriesField(
mainConfig,
detectLanguage(packageJson) === SupportedLanguage.JAVASCRIPT
);

updateStoriesField(mainConfig, detectLanguage(packageJson) === SupportedLanguage.JAVASCRIPT);

// Link in the template/components/index.js from store, the renderer and the addons
const rendererPath = await workspacePath('renderer', template.expected.renderer);
Expand All @@ -345,7 +339,7 @@ export const addStories: Task['run'] = async (
resolve(cwd, storiesPath, 'components')
);
addPreviewAnnotations(mainConfig, [`.${sep}${join(storiesPath, 'components')}`]);

// Add stories for the renderer. NOTE: these *do* need to be processed by the framework build system
await linkPackageStories(rendererPath, {
mainConfig,
Expand Down
5 changes: 3 additions & 2 deletions scripts/tasks/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export const sandbox: Task = {
await remove(details.sandboxDir);
}
const { create, install, addStories } = await import('./sandbox-parts');

await create(details, options);
await install(details, options);
await addStories(details, options);
if (!options.skipTemplateStories) {
await addStories(details, options);
}
},
};