Skip to content

Commit

Permalink
fix parallelism count
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jun 23, 2023
1 parent 4f7cd07 commit 915c9b1
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 31 deletions.
50 changes: 25 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ jobs:
at: .
- run:
name: Creating Sandboxes
command: yarn task --task sandbox --template $(yarn get-template << pipeline.parameters.workflow >> sandbox) --no-link --start-from=never --junit
command: yarn task --task sandbox --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task sandbox) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> sandbox)
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task sandbox)
- persist_to_workspace:
root: .
paths:
Expand All @@ -294,9 +294,9 @@ jobs:
at: .
- run:
name: Smoke Testing Sandboxes
command: yarn task --task smoke-test --template $(yarn get-template << pipeline.parameters.workflow >> smoke-test) --no-link --start-from=never --junit
command: yarn task --task smoke-test --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task smoke-test) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> smoke-test)
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task smoke-test)
- store_test_results:
path: test-results
build-sandboxes:
Expand All @@ -320,13 +320,13 @@ jobs:
background: true
- run:
name: Building Sandboxes
command: yarn task --task build --template $(yarn get-template << pipeline.parameters.workflow >> build) --no-link --start-from=never --junit
command: yarn task --task build --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task build) --no-link --start-from=never --junit
- run:
name: Verifying Telemetry
command: yarn ts-node ./event-log-checker build $(yarn get-template << pipeline.parameters.workflow >> build)
command: yarn ts-node ./event-log-checker build $(yarn get-template --cadence << pipeline.parameters.workflow >> --task build)
working_directory: scripts
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> build)
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task build)
- store_test_results:
path: test-results
- persist_to_workspace:
Expand All @@ -350,9 +350,9 @@ jobs:
at: .
- run:
name: Running Test Runner
command: yarn task --task test-runner --template $(yarn get-template << pipeline.parameters.workflow >> test-runner) --no-link --start-from=never --junit
command: yarn task --task test-runner --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task test-runner) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> test-runner)
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task test-runner)
- store_test_results:
path: test-results
test-runner-dev:
Expand All @@ -371,9 +371,9 @@ jobs:
at: .
- run:
name: Running Test Runner in Dev mode
command: yarn task --task test-runner-dev --template $(yarn get-template << pipeline.parameters.workflow >> test-runner-dev) --no-link --start-from=never --junit
command: yarn task --task test-runner-dev --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task test-runner-dev) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> test-runner-dev)
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task test-runner-dev)
- store_test_results:
path: test-results
chromatic-sandboxes:
Expand All @@ -391,9 +391,9 @@ jobs:
at: .
- run:
name: Running Chromatic
command: yarn task --task chromatic --template $(yarn get-template << pipeline.parameters.workflow >> chromatic) --no-link --start-from=never --junit
command: yarn task --task chromatic --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task chromatic) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> chromatic)
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task chromatic)
- store_test_results:
path: test-results
e2e-production:
Expand All @@ -412,9 +412,9 @@ jobs:
at: .
- run:
name: Running E2E Tests
command: yarn task --task e2e-tests --template $(yarn get-template << pipeline.parameters.workflow >> e2e-tests) --no-link --start-from=never --junit
command: yarn task --task e2e-tests --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task e2e-tests) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> e2e-tests)
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task e2e-tests)
- store_test_results:
path: test-results
- store_artifacts: # this is where playwright puts more complex stuff
Expand All @@ -436,9 +436,9 @@ jobs:
at: .
- run:
name: Running E2E Tests
command: yarn task --task e2e-tests-dev --template $(yarn get-template << pipeline.parameters.workflow >> e2e-tests-dev) --no-link --start-from=never --junit
command: yarn task --task e2e-tests-dev --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task e2e-tests-dev) --no-link --start-from=never --junit
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> e2e-tests-dev)
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task e2e-tests-dev)
- store_test_results:
path: test-results
- store_artifacts: # this is where playwright puts more complex stuff
Expand All @@ -460,12 +460,12 @@ jobs:
at: .
- run:
name: Running Bench
command: yarn task --task bench --template $(yarn get-template << pipeline.parameters.workflow >> bench) --no-link --start-from=never --junit
command: yarn task --task bench --template $(yarn get-template --cadence << pipeline.parameters.workflow >> --task bench) --no-link --start-from=never --junit
- run:
name: Uploading results
command: yarn upload-bench $(yarn get-template << pipeline.parameters.workflow >> bench)
command: yarn upload-bench $(yarn get-template --cadence << pipeline.parameters.workflow >> --task bench)
- report-workflow-on-failure:
template: $(yarn get-template << pipeline.parameters.workflow >> bench)
template: $(yarn get-template --cadence << pipeline.parameters.workflow >> --task bench)

workflows:
ci:
Expand Down Expand Up @@ -601,19 +601,19 @@ workflows:
requires:
- create-sandboxes
- chromatic-sandboxes:
parallelism: 20
parallelism: 18
requires:
- build-sandboxes
- e2e-production:
parallelism: 20
parallelism: 18
requires:
- build-sandboxes
- e2e-dev:
parallelism: 4
requires:
- create-sandboxes
- test-runner-production:
parallelism: 20
parallelism: 18
requires:
- build-sandboxes
- bench:
Expand Down Expand Up @@ -647,14 +647,14 @@ workflows:
requires:
- build
- create-sandboxes:
parallelism: 32
parallelism: 34
requires:
- build
# - smoke-test-sandboxes: # disabled for now
# requires:
# - create-sandboxes
- build-sandboxes:
parallelism: 32
parallelism: 34
requires:
- create-sandboxes
- chromatic-sandboxes:
Expand Down
83 changes: 77 additions & 6 deletions scripts/get-template.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { readdir } from 'fs/promises';
import { pathExists } from 'fs-extra';
import { program } from 'commander';
import dedent from 'ts-dedent';
import {
allTemplates,
templatesByCadence,
Expand Down Expand Up @@ -54,35 +56,104 @@ export async function getTemplate(
});

if (potentialTemplateKeys.length !== total) {
throw new Error(`Circle parallelism set incorrectly.
throw new Error(dedent`Circle parallelism set incorrectly.
Parallelism is set to ${total}, but there are ${
potentialTemplateKeys.length
} templates to run:
${potentialTemplateKeys.join(', ')}
${potentialTemplateKeys.map((v) => `- ${v}`).join('\n')}
${await getParallelismSummary(cadence)}
`);
}

return potentialTemplateKeys[index];
}

async function run() {
const [, , cadence, scriptName] = process.argv;
const tasks = [
'sandbox',
'build',
'chromatic',
'e2e-tests',
'e2e-tests-dev',
'test-runner',
// 'test-runner-dev', TODO: bring this back when the task is enabled again
'bench',
];

async function getParallelismSummary(cadence?: Cadence, scriptName?: string) {
let potentialTemplateKeys: TemplateKey[] = [];
const cadences = cadence ? [cadence] : (Object.keys(templatesByCadence) as Cadence[]);
const scripts = scriptName ? [scriptName] : tasks;
const summary = [];
summary.push('These are the values you should have in .circleci/config.yml:');
cadences.forEach((cad) => {
summary.push(`\n${cad}`);
const cadenceTemplates = Object.entries(allTemplates).filter(([key]) =>
templatesByCadence[cad].includes(key as TemplateKey)
);
potentialTemplateKeys = cadenceTemplates.map(([k]) => k) as TemplateKey[];

scripts.forEach((script) => {
const templateKeysPerScript = potentialTemplateKeys.filter((t) => {
const currentTemplate = allTemplates[t] as Template;
return (
currentTemplate.inDevelopment !== true &&
!currentTemplate.skipTasks?.includes(script as SkippableTask)
);
});
if (templateKeysPerScript.length > 0) {
summary.push(
`-- ${script} - parallelism: ${templateKeysPerScript.length}${
templateKeysPerScript.length === 2 ? ' (default)' : ''
}`
);
} else {
summary.push(`-- ${script} - this script is fully skipped for this cadence.`);
}
});
});

return summary.concat('\n').join('\n');
}

type RunOptions = { cadence?: Cadence; task?: string; debug: boolean };
async function run({ cadence, task, debug }: RunOptions) {
if (debug) {
if (task && !(task in tasks)) {
throw new Error(
dedent`The "${task}" task you provided is not valid. Valid tasks (found in .circleci/config.yml) are:
${tasks.map((v) => `- ${v}`).join('\n')}`
);
}
console.log(await getParallelismSummary(cadence as Cadence, task));
return;
}

if (!cadence) throw new Error('Need to supply cadence to get template script');

const { CIRCLE_NODE_INDEX = 0, CIRCLE_NODE_TOTAL = 1 } = process.env;

console.log(
await getTemplate(cadence as Cadence, scriptName, {
await getTemplate(cadence as Cadence, task, {
index: +CIRCLE_NODE_INDEX,
total: +CIRCLE_NODE_TOTAL,
})
);
}

if (require.main === module) {
run().catch((err) => {
program
.description('Retrieve the template to run for a given cadence and task')
.option('--cadence <cadence>', 'Which cadence you want to run the script for')
.option('--task <task>', 'Which task you want to run the script for')
.option('--debug', 'Whether to list the parallelism counts for tasks by cadence', false);

program.parse(process.argv);

const options = program.opts() as RunOptions;

run(options).catch((err) => {
console.error(err);
process.exit(1);
});
Expand Down

0 comments on commit 915c9b1

Please sign in to comment.