Skip to content

Commit

Permalink
add exec_wrapper function
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Fyson committed Aug 24, 2020
1 parent bd54c20 commit 2b27c68
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/codeql.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/codeql.js.map

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions lib/exec_wrapper.js

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

1 change: 1 addition & 0 deletions lib/exec_wrapper.js.map

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

3 changes: 2 additions & 1 deletion src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import uuidV4 from 'uuid/v4';

import * as api from './api-client';
import * as defaults from './defaults.json'; // Referenced from codeql-action-sync-tool!
import { exec_wrapper } from './exec_wrapper';
import { Language } from './languages';
import * as util from './util';

Expand Down Expand Up @@ -390,7 +391,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
]);
},
finalizeDatabase: async function(databasePath: string) {
await exec.exec(cmd, [
await exec_wrapper(cmd, [
'database',
'finalize',
...getExtraOptionsFromEnv(['database', 'finalize']),
Expand Down
39 changes: 39 additions & 0 deletions src/exec_wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as exec from '@actions/exec';
import * as im from '@actions/exec/lib/interfaces';

export async function exec_wrapper(commandLine: string, args?: string[], options?: im.ExecOptions): Promise<number> {

const originalListener = options?.listeners;

let stdout = '';
let stderr = '';

let listeners = {
stdout: (data: Buffer) => {
stdout += data.toString();
// NB change behaviour to only write to stdout/err if no listener passed
process.stdout.write(data);
originalListener?.stdout?.(data);
},
stderr: (data: Buffer) => {
stderr += data.toString();
process.stderr.write(data);
originalListener?.stderr?.(data);
}
};

const returnCode = await exec.exec(
commandLine,
args,
{
listeners: listeners,
...options
});

if (stderr === stdout ) {
console.log('foo bar');
}

return returnCode;

}

0 comments on commit 2b27c68

Please sign in to comment.