|
|
#!/usr/bin/env node |
|
|
import { basename, dirname } from 'node:path'; |
|
|
import util from 'node:util'; |
|
|
import glob from 'glob'; |
|
|
import runTask from './teamcity-task-runner.mjs'; |
|
|
|
|
|
|
|
|
|
|
|
const APPS_EXCLUDED_FROM_TYPE_CHECK = [ |
|
|
'happy-blocks', |
|
|
'o2-blocks', |
|
|
'odyssey-stats', |
|
|
'notifications', |
|
|
'wpcom-block-editor', |
|
|
]; |
|
|
|
|
|
const globPromise = util.promisify( glob ); |
|
|
|
|
|
|
|
|
async function completeTasks( promises ) { |
|
|
const results = await Promise.allSettled( promises ); |
|
|
const exitCodes = results |
|
|
.filter( ( { status } ) => status === 'rejected' ) |
|
|
.map( ( { reason } ) => reason ); |
|
|
if ( exitCodes.length ) { |
|
|
throw exitCodes[ 0 ]; |
|
|
} |
|
|
} |
|
|
|
|
|
function withTscInfo( { cmd, id } ) { |
|
|
return { |
|
|
testId: id, |
|
|
name: 'yarn', |
|
|
args: cmd, |
|
|
env: { NODE_ENV: 'test' }, |
|
|
}; |
|
|
} |
|
|
|
|
|
function withUnitTestInfo( cmd ) { |
|
|
return { |
|
|
testId: cmd.split( ' ' )[ 0 ], |
|
|
name: 'yarn', |
|
|
args: `${ cmd } --ci --reporters=default --reporters=jest-teamcity --silent`, |
|
|
}; |
|
|
} |
|
|
|
|
|
const [ packagesTsconfigs, appsTsconfigs ] = await Promise.all( |
|
|
[ 'packages', 'apps' ].map( ( path ) => globPromise( `${ path }/*/tsconfig.json` ) ) |
|
|
); |
|
|
|
|
|
const isTypeCheckedApp = ( path ) => |
|
|
! APPS_EXCLUDED_FROM_TYPE_CHECK.includes( basename( dirname( path ) ) ); |
|
|
|
|
|
const tscPackages = withTscInfo( { |
|
|
cmd: `tsc --build ${ packagesTsconfigs.join( ' ' ) }`, |
|
|
id: 'type_check_packages', |
|
|
} ); |
|
|
|
|
|
const tscCommands = [ |
|
|
{ cmd: 'tsc --noEmit --project build-tools/tsconfig.json', id: 'type_check_build_tools' }, |
|
|
{ cmd: 'tsc --noEmit --project client/tsconfig.json', id: 'type_check_client' }, |
|
|
{ cmd: 'tsc --noEmit --project test/e2e/tsconfig.json', id: 'type_check_tests' }, |
|
|
...appsTsconfigs.filter( isTypeCheckedApp ).map( ( path ) => ( { |
|
|
cmd: `tsc --noEmit --project ${ path }`, |
|
|
id: `type_check_apps_${ basename( dirname( path ) ) }`, |
|
|
} ) ), |
|
|
].map( withTscInfo ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const testClient = withUnitTestInfo( 'test-client --maxWorkers=8 --workerIdleMemoryLimit=1GB' ); |
|
|
const testPackages = withUnitTestInfo( 'test-packages --maxWorkers=4 --workerIdleMemoryLimit=1GB' ); |
|
|
const testServer = withUnitTestInfo( 'test-server --maxWorkers=4 --workerIdleMemoryLimit=1GB' ); |
|
|
const testBuildTools = withUnitTestInfo( |
|
|
'test-build-tools --maxWorkers=4 --workerIdleMemoryLimit=1GB' |
|
|
); |
|
|
|
|
|
const testApps = withUnitTestInfo( 'test-apps --maxWorkers=1 --workerIdleMemoryLimit=1GB' ); |
|
|
|
|
|
const testWorkspaces = { |
|
|
name: 'yarn', |
|
|
args: 'workspaces foreach -A --verbose --parallel run storybook:start --ci --smoke-test', |
|
|
testId: 'check_storybook', |
|
|
}; |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
const testClientTask = runTask( testClient ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tscTasks = ( async () => { |
|
|
|
|
|
await runTask( tscPackages ); |
|
|
await completeTasks( tscCommands.map( runTask ) ); |
|
|
} )(); |
|
|
|
|
|
|
|
|
const otherTestTasks = ( async () => { |
|
|
await runTask( testPackages ); |
|
|
await runTask( testServer ); |
|
|
await runTask( testBuildTools ); |
|
|
await runTask( testWorkspaces ); |
|
|
await runTask( testApps ); |
|
|
} )(); |
|
|
|
|
|
await completeTasks( [ testClientTask, tscTasks, otherTestTasks ] ); |
|
|
} catch ( exitCode ) { |
|
|
console.error( 'One or more tasks failed.' ); |
|
|
process.exit( exitCode ); |
|
|
} |
|
|
|