1
1
import { promises as fs } from 'fs' ;
2
2
import { join , normalize , resolve } from 'path' ;
3
+ import * as stream from 'stream' ;
3
4
4
5
import {
5
6
setFailed ,
6
7
info ,
7
8
debug ,
8
9
setOutput ,
9
10
error as _error ,
10
- warning
11
+ warning ,
12
+ group
11
13
} from '@actions/core' ;
12
14
import { exec as _exec , ExecOptions , getExecOutput } from '@actions/exec' ;
13
15
import { getOctokit , context } from '@actions/github' ;
@@ -450,20 +452,34 @@ function render(template: string, vars: TemplateVars): string {
450
452
return _render ( template , vars ) ;
451
453
}
452
454
455
+ async function openDevNullWritable ( ) : Promise < stream . Writable > {
456
+ const file = await fs . open ( '/dev/null' ) ;
457
+ return file . createWriteStream ( ) ;
458
+ }
459
+
453
460
async function execAndSucceed (
454
461
program : string ,
455
462
args : string [ ] ,
456
463
options : ExecOptions = { }
457
464
) : Promise < void > {
458
- debug ( `running ${ program } with arguments: ${ JSON . stringify ( args ) } ` ) ;
459
- const exit = await _exec ( program , args , options ) ;
460
- if ( exit !== 0 ) throw new Error ( `${ program } exited with code ${ exit } ` ) ;
465
+ return await group (
466
+ `running ${ program } with arguments: ${ JSON . stringify ( args ) } ` ,
467
+ async ( ) => {
468
+ const exit = await _exec ( program , args , options ) ;
469
+ if ( exit !== 0 ) {
470
+ throw new Error ( `${ program } exited with code ${ exit } ` ) ;
471
+ }
472
+ }
473
+ ) ;
461
474
}
462
475
463
476
async function toolExists ( name : string ) : Promise < boolean > {
464
477
try {
465
478
debug ( `running "${ name } --help"` ) ;
466
- const code = await _exec ( name , [ '--help' ] ) ;
479
+ const code = await _exec ( name , [ '--help' ] , {
480
+ outStream : await openDevNullWritable ( ) ,
481
+ errStream : await openDevNullWritable ( )
482
+ } ) ;
467
483
debug ( `program exited with code ${ code } ` ) ;
468
484
return code === 0 ;
469
485
} catch ( err ) {
@@ -476,11 +492,16 @@ async function execWithOutput(
476
492
program : string ,
477
493
args : string [ ]
478
494
) : Promise < string > {
479
- debug ( `running ${ program } with arguments: ${ JSON . stringify ( args ) } ` ) ;
480
- const { exitCode, stdout} = await getExecOutput ( program , args ) ;
481
- if ( exitCode !== 0 )
482
- throw new Error ( `${ program } exited with code ${ exitCode } ` ) ;
483
- return stdout ;
495
+ return await group (
496
+ `running ${ program } with arguments: ${ JSON . stringify ( args ) } ` ,
497
+ async ( ) => {
498
+ const { exitCode, stdout} = await getExecOutput ( program , args ) ;
499
+ if ( exitCode !== 0 ) {
500
+ throw new Error ( `${ program } exited with code ${ exitCode } ` ) ;
501
+ }
502
+ return stdout ;
503
+ }
504
+ ) ;
484
505
}
485
506
486
507
function realpath ( path : string ) : string {
0 commit comments