Skip to content

Commit

Permalink
v1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
selfagency committed Sep 19, 2022
1 parent 59a0049 commit ba24216
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ inputs:
description: 'Hide warnings in error output'
type: boolean
required: false
default: false
file:
description: 'Full path to save file'
type: string
required: false
fail:
description: Fail if the command returns a non-zero exit code
type: boolean
required: false
default: true
outputs:
output:
description: 'Output of the command'
stdout:
description: 'Command `stdout` output'
stderr:
description: 'Command `stderr` output'
error-code:
description: 'Command exit code'
duration:
description: 'Duration of the command in seconds'
runs:
Expand Down
13 changes: 6 additions & 7 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3222,14 +3222,10 @@ var import_perf_hooks = require("perf_hooks");
var import_promises = require("fs/promises");
var import_core = __toESM(require_core(), 1);
var import_exec = __toESM(require_exec(), 1);
var errorOut = (data, hideWarning = false, fail = true) => {
var errorOut = (data, hideWarning = false) => {
var _a, _b, _c;
if (((_a = data == null ? void 0 : data.toLowerCase()) == null ? void 0 : _a.includes("error")) && !((_b = data == null ? void 0 : data.toLowerCase()) == null ? void 0 : _b.includes("warn")) && !(data == null ? void 0 : data.includes("ESLint must be installed")) && !(data == null ? void 0 : data.startsWith("error Command failed."))) {
if (fail) {
import_core.default.setFailed(data);
} else {
import_core.default.error(data);
}
import_core.default.error(data);
} else if (!hideWarning && ((_c = data == null ? void 0 : data.toLowerCase()) == null ? void 0 : _c.includes("warn"))) {
import_core.default.warning(data);
} else {
Expand Down Expand Up @@ -3259,7 +3255,7 @@ var errorOut = (data, hideWarning = false, fail = true) => {
stderr: (data) => {
stderr += data.toString();
output += data.toString();
errorOut(data.toString(), hideWarning, fail);
errorOut(data.toString(), hideWarning);
}
}
});
Expand All @@ -3278,6 +3274,9 @@ ${output}`);
if (file) {
await (0, import_promises.writeFile)(file, output);
}
if (fail && exitCode != 0) {
import_core.default.setFailed(stderr);
}
} catch (err) {
import_core.default.setFailed(err.message);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capture-output",
"version": "1.0.4",
"version": "1.0.5",
"description": "Capture the output (and duration) of a command as a GitHub Actions `output` or file",
"repository": {
"type": "git",
Expand Down
14 changes: 7 additions & 7 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ import { writeFile } from 'fs/promises';
import core from '@actions/core';
import exec from '@actions/exec';

const errorOut = (data: string, hideWarning = false, fail = true) => {
const errorOut = (data: string, hideWarning = false) => {
if (
data?.toLowerCase()?.includes('error') &&
!data?.toLowerCase()?.includes('warn') &&
!data?.includes('ESLint must be installed') &&
!data?.startsWith('error Command failed.')
) {
if (fail) {
core.setFailed(data);
} else {
core.error(data);
}
core.error(data);
} else if (!hideWarning && data?.toLowerCase()?.includes('warn')) {
core.warning(data);
} else {
Expand Down Expand Up @@ -47,7 +43,7 @@ const errorOut = (data: string, hideWarning = false, fail = true) => {
stderr: (data: Buffer) => {
stderr += data.toString();
output += data.toString();
errorOut(data.toString(), hideWarning, fail);
errorOut(data.toString(), hideWarning);
}
}
});
Expand All @@ -67,6 +63,10 @@ const errorOut = (data: string, hideWarning = false, fail = true) => {
if (file) {
await writeFile(file, output);
}

if (fail && exitCode != 0) {
core.setFailed(stderr);
}
} catch (err) {
core.setFailed((<Error>err).message);
}
Expand Down

0 comments on commit ba24216

Please sign in to comment.