-
Notifications
You must be signed in to change notification settings - Fork 59
feat(ng-dev): create workflow performance testing tooling #2418
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
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| diff --git a/ng-dev/utils/test/g3.spec.ts b/ng-dev/utils/test/g3.spec.ts | ||
| index a82c1b7a..8e0b24f8 100644 | ||
| --- a/ng-dev/utils/test/g3.spec.ts | ||
| +++ b/ng-dev/utils/test/g3.spec.ts | ||
| @@ -29,9 +29,9 @@ describe('G3Stats', () => { | ||
| }); | ||
|
|
||
| function setupFakeSyncConfig(config: GoogleSyncConfig): string { | ||
| - const configFileName = 'sync-test-conf.json'; | ||
| - fs.writeFileSync(path.join(git.baseDir, configFileName), JSON.stringify(config)); | ||
| - return configFileName; | ||
| + const somethingelse = 'sync-test-conf.json'; | ||
| + fs.writeFileSync(path.join(git.baseDir, somethingelse), JSON.stringify(config)); | ||
| + return somethingelse; | ||
| } | ||
|
|
||
| describe('gathering stats', () => { | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| workflows: | ||
| - name: Rerun a test | ||
| prepare: | | ||
| bazel clean; | ||
| bazel build //ng-dev/utils/test; | ||
| workflow: | | ||
| bazel test //ng-dev/utils/test; | ||
| git apply .ng-dev/perf-tests/test-rerun.diff; | ||
| bazel test //ng-dev/utils/test; | ||
| cleanup: | | ||
| git apply -R .ng-dev/perf-tests/test-rerun.diff; | ||
|
|
||
| - name: Build Everything | ||
| prepare: | | ||
| bazel clean; | ||
| workflow: | | ||
| bazel build //...; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| load("//tools:defaults.bzl", "ts_library") | ||
|
|
||
| ts_library( | ||
| name = "perf", | ||
| srcs = ["cli.ts"], | ||
| visibility = ["//ng-dev:__subpackages__"], | ||
| deps = [ | ||
| "//ng-dev/perf/workflow", | ||
| "@npm//@types/yargs", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
|
|
||
| import {Argv} from 'yargs'; | ||
|
|
||
| import {WorkflowsModule} from './workflow/cli.js'; | ||
|
|
||
| /** Build the parser for pull request commands. */ | ||
| export function buildPerfParser(localYargs: Argv) { | ||
| return localYargs.help().strict().demandCommand().command(WorkflowsModule); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| load("//tools:defaults.bzl", "ts_library") | ||
|
|
||
| ts_library( | ||
| name = "workflow", | ||
| srcs = glob(["*.ts"]), | ||
| visibility = ["//ng-dev:__subpackages__"], | ||
| deps = [ | ||
| "//ng-dev/utils", | ||
| "@npm//@types/node", | ||
| "@npm//@types/yargs", | ||
| "@npm//yaml", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
|
|
||
| import {Argv, CommandModule} from 'yargs'; | ||
| import {measureWorkflow} from './workflow.js'; | ||
| import {loadWorkflows} from './loader.js'; | ||
| import {join} from 'path'; | ||
| import {determineRepoBaseDirFromCwd} from '../../utils/repo-directory.js'; | ||
|
|
||
| interface WorkflowsParams { | ||
| configFile: string; | ||
| json: boolean; | ||
| } | ||
|
|
||
| /** Builds the checkout pull request command. */ | ||
| function builder(yargs: Argv) { | ||
| return yargs | ||
| .option('config-file' as 'configFile', { | ||
| default: '.ng-dev/workflows.yml', | ||
josephperrott marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| type: 'string', | ||
| description: 'The path to the workflow definitions in a yml file', | ||
| }) | ||
| .option('json', { | ||
| default: false, | ||
| type: 'boolean', | ||
| description: 'Whether to ouput the results as a json object', | ||
josephperrott marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
|
|
||
| /** Handles the checkout pull request command. */ | ||
| async function handler({configFile, json}: WorkflowsParams) { | ||
| const workflows = await loadWorkflows(join(determineRepoBaseDirFromCwd(), configFile)); | ||
| const results: {[key: string]: number} = {}; | ||
| for (const workflow of workflows) { | ||
| const {name, duration} = await measureWorkflow(workflow); | ||
| results[name] = duration; | ||
| } | ||
|
|
||
| if (json) { | ||
| process.stdout.write(JSON.stringify(results)); | ||
| } | ||
| } | ||
|
|
||
| /** yargs command module for checking out a PR */ | ||
| export const WorkflowsModule: CommandModule<{}, WorkflowsParams> = { | ||
| handler, | ||
| builder, | ||
| command: 'workflows', | ||
| describe: 'Evaluate the performance of the provided workflows', | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import {readFile} from 'fs/promises'; | ||
| import {parse} from 'yaml'; | ||
|
|
||
| export interface Workflow { | ||
| name: string; | ||
| workflow: string; | ||
| prepare?: string; | ||
| cleanup?: string; | ||
| } | ||
|
|
||
| export async function loadWorkflows(src: string) { | ||
| const rawWorkflows = await readFile(src, {encoding: 'utf-8'}); | ||
| return parse(rawWorkflows).workflows as Workflow[]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import {ChildProcess} from '../../utils/child-process.js'; | ||
| import {green} from '../../utils/logging.js'; | ||
| import {Spinner} from '../../utils/spinner.js'; | ||
| import {Workflow} from './loader.js'; | ||
|
|
||
| export async function measureWorkflow({name, workflow, prepare, cleanup}: Workflow) { | ||
| const spinner = new Spinner(''); | ||
| try { | ||
| if (prepare) { | ||
| spinner.update('Preparing environment for workflow execution'); | ||
| // Run the `prepare` commands to establish the environment, caching, etc prior to running the | ||
| // workflow. | ||
| await runCommands(prepare); | ||
| spinner.update('Environment preperation completed'); | ||
| } | ||
|
|
||
| spinner.update(`Executing workflow (${name})`); | ||
| // Mark the start time of the workflow, execute all of the commands provided in the workflow and | ||
| // then mark the ending time. | ||
| performance.mark('start'); | ||
| await runCommands(workflow); | ||
| performance.mark('end'); | ||
|
|
||
| spinner.update('Workflow completed'); | ||
|
|
||
| if (cleanup) { | ||
| spinner.update('Cleaning up environment after workflow'); | ||
| // Run the clean up commands to reset the environment and undo changes made during the workflow. | ||
| await runCommands(cleanup); | ||
| spinner.update('Environment cleanup complete'); | ||
| } | ||
|
|
||
| const results = performance.measure(name, 'start', 'end'); | ||
|
|
||
| spinner.complete(` ${green('✓')} ${name}: ${results.duration.toFixed(2)}ms`); | ||
|
|
||
| return results.toJSON(); | ||
| } finally { | ||
| spinner.complete(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Run a set of commands provided as a multiline text block. Commands are assumed to always be | ||
| * provided on a single line. | ||
| */ | ||
| async function runCommands(cmds?: string) { | ||
| cmds = cmds?.trim(); | ||
| if (!cmds) { | ||
| return; | ||
| } | ||
| let commands = cmds | ||
| .split('\n') | ||
| .filter((_) => !!_) | ||
josephperrott marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .map((cmdStr: string) => cmdStr.trim().split(' ')); | ||
josephperrott marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for (let [cmd, ...args] of commands) { | ||
| await ChildProcess.spawn(cmd, args, {mode: 'silent'}); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.