Skip to content

Commit

Permalink
Merge pull request #24582 from storybookjs/kasper/bench-sandboxes
Browse files Browse the repository at this point in the history
Build: Add new sandboxes for test build benchmarks
  • Loading branch information
kasperpeulen authored Oct 26, 2023
2 parents 2a0cd91 + c2ac545 commit ece2d24
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 89 deletions.
38 changes: 0 additions & 38 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,30 +341,6 @@ jobs:
paths:
- sandbox/*/bench/*.json
- sandbox/*/storybook-static
build-test-sandboxes:
parameters:
parallelism:
type: integer
executor:
class: large
name: sb_node_16_browsers
parallelism: << parameters.parallelism >>
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
- attach_workspace:
at: .
- run:
name: Building Sandboxes
command: yarn task --task test-build --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task build) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task build)
- store_test_results:
path: test-results
- persist_to_workspace:
root: .
paths:
- sandbox/*/bench/test-build.json
test-runner-production:
parameters:
parallelism:
Expand Down Expand Up @@ -526,10 +502,6 @@ workflows:
parallelism: 12
requires:
- build
- build-test-sandboxes:
parallelism: 12
requires:
- create-sandboxes
- build-sandboxes:
parallelism: 12
requires:
Expand All @@ -554,7 +526,6 @@ workflows:
parallelism: 3
requires:
- build-sandboxes
- build-test-sandboxes
# TODO: reenable once we find out the source of flakyness
# - test-runner-dev:
# requires:
Expand Down Expand Up @@ -587,10 +558,6 @@ workflows:
parallelism: 21
requires:
- build
- build-test-sandboxes:
parallelism: 21
requires:
- create-sandboxes
- build-sandboxes:
parallelism: 21
requires:
Expand All @@ -615,7 +582,6 @@ workflows:
parallelism: 3
requires:
- build-sandboxes
- build-test-sandboxes
# TODO: reenable once we find out the source of flakyness
# - test-runner-dev:
# parallelism: 4
Expand Down Expand Up @@ -649,10 +615,6 @@ workflows:
# - smoke-test-sandboxes: # disabled for now
# requires:
# - create-sandboxes
- build-test-sandboxes:
parallelism: 36
requires:
- create-sandboxes
- build-sandboxes:
parallelism: 36
requires:
Expand Down
27 changes: 26 additions & 1 deletion code/lib/cli/src/sandbox-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type Template = {
modifications?: {
skipTemplateStories?: boolean;
mainConfig?: Partial<StorybookConfig>;
testBuild?: boolean;
disableDocs?: boolean;
};
/**
Expand Down Expand Up @@ -559,7 +560,29 @@ const benchTemplates = {
},
skipTasks: ['e2e-tests-dev', 'test-runner', 'test-runner-dev', 'e2e-tests', 'chromatic'],
},
} satisfies Record<`bench/${string}`, Template & { isInternal: true }>;
'bench/react-vite-default-ts-test-build': {
...baseTemplates['react-vite/default-ts'],
name: 'Bench (react-vite/default-ts, test-build)',
inDevelopment: true,
isInternal: true,
modifications: {
skipTemplateStories: true,
testBuild: true,
},
skipTasks: ['e2e-tests-dev', 'test-runner', 'test-runner-dev', 'e2e-tests', 'chromatic'],
},
'bench/react-webpack-18-ts-test-build': {
...baseTemplates['react-webpack/18-ts'],
name: 'Bench (react-webpack/18-ts, test-build)',
inDevelopment: true,
isInternal: true,
modifications: {
skipTemplateStories: true,
testBuild: true,
},
skipTasks: ['e2e-tests-dev', 'test-runner', 'test-runner-dev', 'e2e-tests', 'chromatic'],
},
} satisfies Record<string, Template & { isInternal: true }>;

export const allTemplates: Record<TemplateKey, Template> = {
...baseTemplates,
Expand All @@ -580,6 +603,8 @@ export const normal: TemplateKey[] = [
'bench/react-vite-default-ts',
'bench/react-webpack-18-ts',
'bench/react-vite-default-ts-nodocs',
'bench/react-vite-default-ts-test-build',
'bench/react-webpack-18-ts-test-build',
];
export const merged: TemplateKey[] = [
...normal,
Expand Down
3 changes: 1 addition & 2 deletions scripts/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { sandbox } from './tasks/sandbox';
import { syncDocs } from './tasks/sync-docs';
import { dev } from './tasks/dev';
import { smokeTest } from './tasks/smoke-test';
import { build, testBuild } from './tasks/build';
import { build } from './tasks/build';
import { serve } from './tasks/serve';
import { testRunnerBuild } from './tasks/test-runner-build';
import { testRunnerDev } from './tasks/test-runner-dev';
Expand Down Expand Up @@ -103,7 +103,6 @@ export const tasks = {
dev,
'smoke-test': smokeTest,
build,
'test-build': testBuild,
serve,
'test-runner': testRunnerBuild,
'test-runner-dev': testRunnerDev,
Expand Down
54 changes: 6 additions & 48 deletions scripts/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ export const build: Task = {
async ready({ builtSandboxDir }) {
return pathExists(builtSandboxDir);
},
async run({ sandboxDir }, { dryRun, debug }) {
async run({ sandboxDir, template }, { dryRun, debug }) {
const start = now();

await exec(`yarn build-storybook --quiet`, { cwd: sandboxDir }, { dryRun, debug });
await exec(
`yarn build-storybook --quiet ${template.modifications?.testBuild ? '--test' : ''}`,
{ cwd: sandboxDir },
{ dryRun, debug }
);

const buildTime = now() - start;
const dir = join(sandboxDir, 'storybook-static');
Expand Down Expand Up @@ -48,49 +52,3 @@ export const build: Task = {
);
},
};

export const testBuild: Task = {
description: 'Build the static version of the sandbox optimized for testing purposes',
dependsOn: ['sandbox'],
async ready({ builtSandboxDir }) {
return pathExists(builtSandboxDir);
},
async run({ sandboxDir }, { dryRun, debug }) {
const start = now();

await exec(`yarn build-storybook --test --quiet`, { cwd: sandboxDir }, { dryRun, debug });

const testBuildTime = now() - start;
const dir = join(sandboxDir, 'storybook-static');
const getSize = promisify(dirSize);
const testBuildSize = await getSize(dir);
const testBuildSbAddonsSize = await getSize(join(dir, 'sb-addons'));
const testBuildSbCommonSize = await getSize(join(dir, 'sb-common-assets'));
const testBuildSbManagerSize = await getSize(join(dir, 'sb-manager'));
const testBuildSbPreviewSize = await getSize(join(dir, 'sb-preview'));
const testBuildPrebuildSize =
testBuildSbAddonsSize +
testBuildSbCommonSize +
testBuildSbManagerSize +
testBuildSbPreviewSize;

const testBuildStaticSize = await getSize(join(dir, 'static')).catch(() => 0);
const testBuildPreviewSize = testBuildSize - testBuildPrebuildSize - testBuildStaticSize;

await saveBench(
'test-build',
{
testBuildTime,
testBuildSize,
testBuildSbAddonsSize,
testBuildSbCommonSize,
testBuildSbManagerSize,
testBuildSbPreviewSize,
testBuildStaticSize,
testBuildPrebuildSize,
testBuildPreviewSize,
},
{ rootDir: sandboxDir }
);
},
};

0 comments on commit ece2d24

Please sign in to comment.