Skip to content
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

Add retrying CI test support #17219

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions scripts/ci/check-unit-tests-for-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ main()
} );

async function main() {
const { packageName, checkCoverage, allowNonFullCoverage, coverageFile } = getOptions( process.argv.slice( 2 ) );
const { packageName, checkCoverage, allowNonFullCoverage, coverageFile, attempts } = getOptions( process.argv.slice( 2 ) );

runTests( { packageName, checkCoverage } );
runTests( { packageName, checkCoverage, attempts } );

if ( checkCoverage && !allowNonFullCoverage ) {
const exitCode = checkCodeCoverage();
Expand All @@ -46,8 +46,9 @@ async function main() {
* @param {Object} options
* @param {String} options.packageName
* @param {Boolean} options.checkCoverage
* @param {Number} options.attempts
*/
function runTests( { packageName, checkCoverage } ) {
function runTests( { packageName, checkCoverage, attempts = 3 } ) {
const shortName = packageName.replace( /^ckeditor5?-/, '' );

const testCommand = [
Expand All @@ -59,10 +60,24 @@ function runTests( { packageName, checkCoverage } ) {
checkCoverage ? '--coverage' : null
].filter( Boolean );

execSync( testCommand.join( ' ' ), {
cwd: CKEDITOR5_ROOT_PATH,
stdio: 'inherit'
} );
try {
execSync( testCommand.join( ' ' ), {
cwd: CKEDITOR5_ROOT_PATH,
stdio: 'inherit'
} );
} catch ( err ) {
if ( !attempts ) {
throw err;
}

console.log( `\n⚠️ Retry the test execution. Remaining attempts: ${ attempts - 1 }.` );

return runTests( {
packageName,
checkCoverage,
attempts: attempts - 1
} );
}
}

function checkCodeCoverage() {
Expand Down Expand Up @@ -90,12 +105,14 @@ function checkCodeCoverage() {
* @returns {Boolean} options.checkCoverage
* @returns {Boolean} options.allowNonFullCoverage
* @returns {String|null} options.coverageFile
* @returns {Number} options.attempts
*/
function getOptions( argv ) {
const options = minimist( argv, {
string: [
'package-name',
'coverage-file'
'coverage-file',
'attempts'
],
boolean: [
'check-coverage',
Expand All @@ -107,6 +124,7 @@ function getOptions( argv ) {
}
} );

options.attempts = Number( options.attempts || 1 );
options.packageName = options[ 'package-name' ];
options.coverageFile = options[ 'coverage-file' ];
options.checkCoverage = options[ 'check-coverage' ];
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/generate-circleci-configuration.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function generateTestSteps( packages, { checkCoverage, coverageFile = null } ) {
const testCommand = [
'node',
'scripts/ci/check-unit-tests-for-package.mjs',
'--attempts 3',
'--package-name',
packageName,
checkCoverage ? '--check-coverage' : null,
Expand Down