|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | + |
| 9 | +import {Argv, CommandModule} from 'yargs'; |
| 10 | +import {measureWorkflow} from './workflow.js'; |
| 11 | +import {loadWorkflows} from './loader.js'; |
| 12 | +import {join} from 'path'; |
| 13 | +import {determineRepoBaseDirFromCwd} from '../../utils/repo-directory.js'; |
| 14 | + |
| 15 | +interface WorkflowsParams { |
| 16 | + configFile: string; |
| 17 | + json: boolean; |
| 18 | +} |
| 19 | + |
| 20 | +/** Builds the checkout pull request command. */ |
| 21 | +function builder(yargs: Argv) { |
| 22 | + return yargs |
| 23 | + .option('config-file' as 'configFile', { |
| 24 | + default: '.ng-dev/workflows.yml', |
| 25 | + type: 'string', |
| 26 | + description: 'The path to the workflow definitions in a yml file', |
| 27 | + }) |
| 28 | + .option('json', { |
| 29 | + default: false, |
| 30 | + type: 'boolean', |
| 31 | + description: 'Whether to ouput the results as a json object', |
| 32 | + }); |
| 33 | +} |
| 34 | + |
| 35 | +/** Handles the checkout pull request command. */ |
| 36 | +async function handler({configFile, json}: WorkflowsParams) { |
| 37 | + const workflows = await loadWorkflows(join(determineRepoBaseDirFromCwd(), configFile)); |
| 38 | + const results: {[key: string]: number} = {}; |
| 39 | + for (const workflow of workflows) { |
| 40 | + const {name, duration} = await measureWorkflow(workflow); |
| 41 | + results[name] = duration; |
| 42 | + } |
| 43 | + |
| 44 | + if (json) { |
| 45 | + process.stdout.write(JSON.stringify(results)); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +/** yargs command module for checking out a PR */ |
| 50 | +export const WorkflowsModule: CommandModule<{}, WorkflowsParams> = { |
| 51 | + handler, |
| 52 | + builder, |
| 53 | + command: 'workflows', |
| 54 | + describe: 'Evaluate the performance of the provided workflows', |
| 55 | +}; |
0 commit comments