File tree Expand file tree Collapse file tree 3 files changed +35
-8
lines changed
Expand file tree Collapse file tree 3 files changed +35
-8
lines changed Original file line number Diff line number Diff line change 5959
6060 - name : Run tests
6161 shell : bash
62- run : npm run test:no-build
62+ # Retry tests if they fail in the merge queue.
63+ run : npm run test:no-build -- ${{ github.event_name == 'merge_group' && '--retry' || '' }}
6364
6465 # Gating job for branch protection.
6566 test-success :
Original file line number Diff line number Diff line change 1616 "docs:generate" : " node --experimental-strip-types scripts/generate-docs.ts" ,
1717 "start" : " npm run build && node build/src/index.js" ,
1818 "start-debug" : " DEBUG=mcp:* DEBUG_COLORS=false npm run build && node build/src/index.js" ,
19- "test" : " npm run build && npm run test:no-build " ,
19+ "test" : " npm run build && node scripts/ test.mjs " ,
2020 "test:no-build" : " node scripts/test.mjs" ,
2121 "test:only" : " npm run build && node scripts/test.mjs --test-only" ,
2222 "test:update-snapshots" : " npm run build && node scripts/test.mjs --test-update-snapshots" ,
Original file line number Diff line number Diff line change @@ -17,6 +17,13 @@ const flags = args.filter(arg => arg.startsWith('-'));
1717
1818const files = [ ] ;
1919
20+ let shouldRetry = false ;
21+ const retryIndex = flags . indexOf ( '--retry' ) ;
22+ if ( retryIndex !== - 1 ) {
23+ shouldRetry = true ;
24+ flags . splice ( retryIndex , 1 ) ;
25+ }
26+
2027if ( userArgs . length > 0 ) {
2128 for ( const arg of userArgs ) {
2229 // Map .ts files to build/ .js files
@@ -50,10 +57,29 @@ const nodeArgs = [
5057 ...files ,
5158] ;
5259
53- const child = spawn ( 'node' , nodeArgs , {
54- stdio : 'inherit' ,
55- } ) ;
60+ async function runTests ( attempt ) {
61+ if ( attempt > 1 ) {
62+ console . log ( `\nRun attempt ${ attempt } ...\n` ) ;
63+ }
64+ return new Promise ( resolve => {
65+ const child = spawn ( 'node' , nodeArgs , {
66+ stdio : 'inherit' ,
67+ } ) ;
68+
69+ child . on ( 'close' , code => {
70+ resolve ( code ) ;
71+ } ) ;
72+ } ) ;
73+ }
74+
75+ const maxAttempts = shouldRetry ? 3 : 1 ;
76+ let exitCode = 1 ;
77+
78+ for ( let i = 1 ; i <= maxAttempts ; i ++ ) {
79+ exitCode = await runTests ( i ) ;
80+ if ( exitCode === 0 ) {
81+ break ;
82+ }
83+ }
5684
57- child . on ( 'close' , code => {
58- process . exit ( code ?? 1 ) ;
59- } ) ;
85+ process . exit ( exitCode ?? 1 ) ;
You can’t perform that action at this time.
0 commit comments