Skip to content

Commit

Permalink
ensure matchers not applied if exit code is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Fyson committed Sep 3, 2020
1 parent 231537b commit 6a43a61
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/exec_wrapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/exec_wrapper.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/exec_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as exec from '@actions/exec';
import * as im from '@actions/exec/lib/interfaces';


export type ErrorMatcher = [number, RegExp, string];

/**
* Wrapper for exec.exec which checks for specific return code and/or regex matches in console output.
* Output will be streamed to the live console as well as captured for subsequent processing.
Expand All @@ -14,7 +16,7 @@ import * as im from '@actions/exec/lib/interfaces';
* @returns Promise<number> exit code
*/
export async function exec_wrapper(commandLine: string, args?: string[],
matchers?: [[number, RegExp, string]],
matchers?: ErrorMatcher[],
options?: im.ExecOptions): Promise<number> {

let stdout = '';
Expand Down Expand Up @@ -58,7 +60,7 @@ export async function exec_wrapper(commandLine: string, args?: string[],
originalReturnValue = e;
}

if (matchers) {
if (matchers && originalReturnValue !== 0) {
for (const [customCode, regex, message] of matchers) {
if (customCode === originalReturnValue || regex.test(stderr) || regex.test(stdout) ) {
throw new Error(message);
Expand Down

0 comments on commit 6a43a61

Please sign in to comment.