Skip to content

Commit a43e706

Browse files
authored
Reduce output of this action (#115)
1 parent 3642f3e commit a43e706

File tree

3 files changed

+53
-21
lines changed

3 files changed

+53
-21
lines changed

dist/index.js

+21-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {promises as fs} from 'fs';
22
import {join, normalize, resolve} from 'path';
3+
import * as stream from 'stream';
34

45
import {
56
setFailed,
67
info,
78
debug,
89
setOutput,
910
error as _error,
10-
warning
11+
warning,
12+
group
1113
} from '@actions/core';
1214
import {exec as _exec, ExecOptions, getExecOutput} from '@actions/exec';
1315
import {getOctokit, context} from '@actions/github';
@@ -450,20 +452,34 @@ function render(template: string, vars: TemplateVars): string {
450452
return _render(template, vars);
451453
}
452454

455+
async function openDevNullWritable(): Promise<stream.Writable> {
456+
const file = await fs.open('/dev/null');
457+
return file.createWriteStream();
458+
}
459+
453460
async function execAndSucceed(
454461
program: string,
455462
args: string[],
456463
options: ExecOptions = {}
457464
): 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+
);
461474
}
462475

463476
async function toolExists(name: string): Promise<boolean> {
464477
try {
465478
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+
});
467483
debug(`program exited with code ${code}`);
468484
return code === 0;
469485
} catch (err) {
@@ -476,11 +492,16 @@ async function execWithOutput(
476492
program: string,
477493
args: string[]
478494
): 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+
);
484505
}
485506

486507
function realpath(path: string): string {

0 commit comments

Comments
 (0)