Skip to content

Commit 247bd73

Browse files
authored
Merge pull request #33720 from storybookjs/norbert/ci-cost-optimizations
CI: Decrease resource-sizes to lower cost
2 parents 0451427 + 24c37a8 commit 247bd73

File tree

5 files changed

+82
-42
lines changed

5 files changed

+82
-42
lines changed

scripts/check/check-package.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { existsSync } from 'node:fs';
12
import { isAbsolute } from 'node:path';
23
import { parseArgs } from 'node:util';
34

@@ -19,15 +20,17 @@ const normalizedCwd = cwd ? (isAbsolute(cwd) ? cwd : join(ROOT_DIRECTORY, cwd))
1920

2021
const tsconfigPath = join(normalizedCwd, 'tsconfig.json');
2122

22-
const { options, fileNames } = getTSFilesAndConfig(tsconfigPath, normalizedCwd);
23-
const { program, host } = getTSProgramAndHost(fileNames, options);
24-
25-
const tsDiagnostics = getTSDiagnostics(program, normalizedCwd, host);
26-
if (tsDiagnostics.length > 0) {
27-
console.log(tsDiagnostics);
28-
process.exit(1);
29-
} else if (!process.env.CI) {
30-
console.log('✅ No type errors');
23+
if (existsSync(tsconfigPath)) {
24+
const { options, fileNames } = getTSFilesAndConfig(tsconfigPath, normalizedCwd);
25+
const { program, host } = getTSProgramAndHost(fileNames, options);
26+
27+
const tsDiagnostics = getTSDiagnostics(program, normalizedCwd, host);
28+
if (tsDiagnostics.length > 0) {
29+
console.log(tsDiagnostics);
30+
process.exit(1);
31+
} else if (!process.env.CI) {
32+
console.log('✅ No type errors');
33+
}
3134
}
3235

3336
// TODO, add more package checks here, like:

scripts/ci/common-jobs.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export const check = defineJob(
154154
(workflowName) => ({
155155
executor: {
156156
name: 'sb_node_22_classic',
157-
class: 'xlarge',
157+
class: 'medium+',
158158
},
159159
steps: [
160160
...workflow.restoreLinux(),
@@ -184,15 +184,22 @@ export const lint = defineJob(
184184
() => ({
185185
executor: {
186186
name: 'sb_node_22_classic',
187-
class: 'xlarge',
187+
class: 'large',
188188
},
189189
steps: [
190190
...workflow.restoreLinux(),
191191
{
192192
run: {
193-
name: 'Lint code',
193+
name: 'Lint code JS',
194194
working_directory: `code`,
195-
command: 'yarn lint',
195+
command: 'yarn lint:js',
196+
},
197+
},
198+
{
199+
run: {
200+
name: 'Lint code Other',
201+
working_directory: `code`,
202+
command: 'yarn lint:other',
196203
},
197204
},
198205
{
@@ -321,7 +328,7 @@ export const benchmarkPackages = defineJob(
321328
() => ({
322329
executor: {
323330
name: 'sb_node_22_classic',
324-
class: 'large',
331+
class: 'medium+',
325332
},
326333
steps: [
327334
...workflow.restoreLinux(),

scripts/ci/sandboxes.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function defineSandboxJob_build({
3333
() => ({
3434
executor: {
3535
name: 'sb_node_22_classic',
36-
class: 'large',
36+
class: 'medium+',
3737
},
3838
steps: [
3939
...workflow.restoreLinux(),
@@ -68,11 +68,11 @@ function defineSandboxJob_dev({
6868
executor: options.e2e
6969
? {
7070
name: 'sb_playwright',
71-
class: 'xlarge',
71+
class: 'medium+',
7272
}
7373
: {
7474
name: 'sb_node_22_classic',
75-
class: 'large',
75+
class: 'medium',
7676
},
7777
steps: [
7878
...workflow.restoreLinux(),
@@ -267,7 +267,7 @@ export function defineSandboxFlow<Key extends string>(key: Key) {
267267
() => ({
268268
executor: {
269269
name: 'sb_playwright',
270-
class: 'xlarge',
270+
class: 'medium+',
271271
},
272272
steps: [
273273
...workflow.restoreLinux(),
@@ -371,7 +371,7 @@ export function defineWindowsSandboxDev(sandbox: ReturnType<typeof defineSandbox
371371
() => ({
372372
executor: {
373373
name: 'win/default',
374-
size: 'xlarge',
374+
size: 'large',
375375
shell: 'bash.exe',
376376
},
377377
steps: [
@@ -420,7 +420,7 @@ export function defineWindowsSandboxBuild(sandbox: ReturnType<typeof defineSandb
420420
() => ({
421421
executor: {
422422
name: 'win/default',
423-
size: 'xlarge',
423+
size: 'large',
424424
shell: 'bash.exe',
425425
},
426426
steps: [

scripts/ci/test-storybooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function definePortableStoryTest(directory: string) {
2323
() => ({
2424
executor: {
2525
name: 'sb_playwright',
26-
class: 'medium',
26+
class: 'medium+',
2727
},
2828
steps: [
2929
...workflow.restoreLinux(),

scripts/tasks/check.ts

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,62 @@
1-
import type { Task } from '../task';
2-
import { ROOT_DIRECTORY } from '../utils/constants';
3-
import { exec } from '../utils/exec';
4-
import { maxConcurrentTasks } from '../utils/maxConcurrentTasks';
5-
6-
// The amount of VCPUs for the check task on CI is 4 (large resource)
7-
const amountOfVCPUs = 4;
1+
import { join } from 'node:path';
82

9-
const parallel = `--parallel=${process.env.CI ? amountOfVCPUs - 1 : maxConcurrentTasks}`;
3+
// eslint-disable-next-line depend/ban-dependencies
4+
import { execaCommand } from 'execa';
105

11-
const linkCommand = `yarn nx run-many -t check ${parallel}`;
12-
const nolinkCommand = `yarn nx run-many -t check -c production ${parallel}`;
6+
import type { Task } from '../task';
7+
import { CODE_DIRECTORY, ROOT_DIRECTORY } from '../utils/constants';
8+
import { getCodeWorkspaces } from '../utils/workspace';
139

1410
export const check: Task = {
1511
description: 'Typecheck the source code of the monorepo',
1612
async ready() {
1713
return false;
1814
},
19-
async run(_, { dryRun, debug, link, skipCache }) {
20-
const command = link ? linkCommand : nolinkCommand;
21-
return exec(
22-
`${command} ${skipCache || process.env.CI ? '--skip-nx-cache' : ''}`,
23-
{ cwd: ROOT_DIRECTORY },
24-
{
25-
startMessage: '🥾 Checking for TS errors',
26-
errorMessage: '❌ TS errors detected',
27-
dryRun,
28-
debug,
15+
async run(_, {}) {
16+
const failed: string[] = [];
17+
// const command = link ? linkCommand : nolinkCommand;
18+
const workspaces = await getCodeWorkspaces();
19+
20+
for (const workspace of workspaces) {
21+
if (workspace.location === '.') {
22+
continue; // skip root directory
23+
}
24+
const cwd = join(CODE_DIRECTORY, workspace.location);
25+
console.log('');
26+
console.log('Checking ' + workspace.name + ' at ' + cwd);
27+
28+
let command = '';
29+
if (workspace.name === '@storybook/vue3') {
30+
command = `npx vue-tsc --noEmit --project ${join(cwd, 'tsconfig.json')}`;
31+
} else if (workspace.name === '@storybook/svelte') {
32+
command = `npx svelte-check`;
33+
} else {
34+
const script = join(ROOT_DIRECTORY, 'scripts', 'check', 'check-package.ts');
35+
command = `yarn exec jiti ${script} --cwd ${cwd}`;
36+
// command = `npx tsc --noEmit --project ${join(cwd, 'tsconfig.json')}`;
2937
}
30-
);
38+
39+
const sub = execaCommand(`${command}`, {
40+
cwd,
41+
env: {
42+
NODE_ENV: 'production',
43+
},
44+
});
45+
46+
sub.stdout?.on('data', (data) => {
47+
process.stdout.write(data);
48+
});
49+
sub.stderr?.on('data', (data) => {
50+
process.stderr.write(data);
51+
});
52+
53+
await sub.catch(() => {
54+
failed.push(workspace.name);
55+
});
56+
}
57+
58+
if (failed.length > 0) {
59+
throw new Error(`Failed to check ${failed.join(', ')}`);
60+
}
3161
},
3262
};

0 commit comments

Comments
 (0)