@@ -11,11 +11,14 @@ import {measureWorkflow} from './workflow.js';
1111import { loadWorkflows } from './loader.js' ;
1212import { join } from 'path' ;
1313import { determineRepoBaseDirFromCwd } from '../../utils/repo-directory.js' ;
14+ import { addWorkflowPerformanceResult } from './database.js' ;
15+ import { Spinner } from '../../utils/spinner.js' ;
1416
1517interface WorkflowsParams {
1618 configFile : string ;
1719 list : boolean ;
1820 name ?: string ;
21+ commitSha ?: string ;
1922}
2023
2124/** Builds the checkout pull request command. */
@@ -34,30 +37,48 @@ function builder(yargs: Argv) {
3437 . option ( 'name' , {
3538 type : 'string' ,
3639 description : 'A specific workflow to run by name' ,
40+ } )
41+ . option ( 'commit-sha' as 'commitSha' , {
42+ type : 'string' ,
43+ description : 'The commit sha to associate the measurement with, uploading it to our database' ,
3744 } ) ;
3845}
3946
4047/** Handles the checkout pull request command. */
41- async function handler ( { configFile, list, name} : WorkflowsParams ) {
48+ async function handler ( { configFile, list, name, commitSha } : WorkflowsParams ) {
4249 const workflows = await loadWorkflows ( join ( determineRepoBaseDirFromCwd ( ) , configFile ) ) ;
4350
4451 if ( list ) {
4552 process . stdout . write ( JSON . stringify ( Object . keys ( workflows ) ) ) ;
4653 return ;
4754 }
4855
56+ const results : { name : string ; value : number } [ ] = [ ] ;
57+
4958 if ( name ) {
50- const { duration} = await measureWorkflow ( workflows [ name ] ) ;
51- process . stdout . write ( JSON . stringify ( { [ name ] : duration } ) ) ;
52- return ;
59+ const { value} = await measureWorkflow ( workflows [ name ] ) ;
60+ results . push ( { value, name} ) ;
61+ } else {
62+ for ( const workflow of Object . values ( workflows ) ) {
63+ const { name, value} = await measureWorkflow ( workflow ) ;
64+ results . push ( { value, name} ) ;
65+ }
5366 }
5467
55- const results : { [ key : string ] : number } = { } ;
56- for ( const workflow of Object . values ( workflows ) ) {
57- const { name, duration} = await measureWorkflow ( workflow ) ;
58- results [ name ] = duration ;
68+ if ( commitSha ) {
69+ const spinner = new Spinner ( 'Uploading performance results to database' ) ;
70+ try {
71+ for ( let { value, name} of results ) {
72+ await addWorkflowPerformanceResult ( {
73+ name,
74+ value,
75+ commit_sha : commitSha ,
76+ } ) ;
77+ }
78+ } finally {
79+ spinner . success ( 'Upload complete' ) ;
80+ }
5981 }
60- process . stdout . write ( JSON . stringify ( results ) ) ;
6182}
6283
6384/** yargs command module for checking out a PR. */
0 commit comments