[ci-jobs] Adds --list and --json options to save jobs output (#50684)
This commit is contained in:
parent
9b1d91c7d2
commit
ba6f81c486
File diff suppressed because one or more lines are too long
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
import { Command } from '@commander-js/extra-typings';
|
||||
import { setOutput } from '@actions/core';
|
||||
import { writeFileSync } from 'fs';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -27,6 +28,8 @@ const program = new Command( 'ci-jobs' )
|
|||
'Github event for which to run the jobs. If not specified, all events will be considered.',
|
||||
''
|
||||
)
|
||||
.option( '--json', 'Save the jobs in a json file.' )
|
||||
.option( '--list', 'List jobs in table format console.' )
|
||||
.action( async ( options ) => {
|
||||
Logger.startTask( 'Parsing Project Graph', true );
|
||||
const projectGraph = buildProjectGraph();
|
||||
|
@ -113,6 +116,56 @@ const program = new Command( 'ci-jobs' )
|
|||
} else {
|
||||
Logger.notice( `No report jobs to run.` );
|
||||
}
|
||||
|
||||
if ( options.list ) {
|
||||
Object.keys( jobs ).forEach( ( key ) => {
|
||||
const job = jobs[ key ].map(
|
||||
( { name, projectName, optional } ) => ( {
|
||||
name: `${ key } - ${
|
||||
key === 'lint' ? projectName : name
|
||||
}`,
|
||||
optional,
|
||||
} )
|
||||
);
|
||||
// eslint-disable-next-line no-console
|
||||
console.table( job );
|
||||
} );
|
||||
}
|
||||
|
||||
if ( options.json ) {
|
||||
Logger.notice( 'Saving jobs to json file.' );
|
||||
|
||||
Object.keys( jobs ).forEach( ( key ) => {
|
||||
jobs[ key ] = jobs[ key ].map(
|
||||
( {
|
||||
name,
|
||||
projectName,
|
||||
projectPath,
|
||||
testType,
|
||||
optional,
|
||||
} ) => ( {
|
||||
name,
|
||||
projectName,
|
||||
projectPath,
|
||||
testType,
|
||||
optional,
|
||||
} )
|
||||
);
|
||||
} );
|
||||
|
||||
writeFileSync(
|
||||
'jobs.json',
|
||||
JSON.stringify(
|
||||
{
|
||||
baseRef: options.baseRef,
|
||||
event: options.event,
|
||||
...jobs,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
export default program;
|
||||
|
|
Loading…
Reference in New Issue