move error matcher definition into dedicated file
This commit is contained in:
parent
1f3ce75844
commit
7dbaff09b6
11 changed files with 40 additions and 12 deletions
|
|
@ -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 { errorMatchers} from './error_matcher';
|
||||
import { exec_wrapper } from './exec_wrapper';
|
||||
import { Language } from './languages';
|
||||
import * as util from './util';
|
||||
|
|
@ -390,7 +391,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
'--',
|
||||
traceCommand
|
||||
],
|
||||
[[0, new RegExp("(No source code was seen during the build\\.|No JavaScript or TypeScript code found\\.)"), 'foo bar']]
|
||||
errorMatchers
|
||||
);
|
||||
},
|
||||
finalizeDatabase: async function(databasePath: string) {
|
||||
|
|
@ -401,7 +402,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
...getExtraOptionsFromEnv(['database', 'finalize']),
|
||||
databasePath
|
||||
],
|
||||
[[0, new RegExp("(No source code was seen during the build\\.|No JavaScript or TypeScript code found\\.)"), 'foo bar']]);
|
||||
errorMatchers);
|
||||
},
|
||||
resolveQueries: async function(queries: string[], extraSearchPath: string | undefined) {
|
||||
const codeqlArgs = [
|
||||
|
|
|
|||
19
src/error_matcher.ts
Normal file
19
src/error_matcher.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
export type ErrorMatcher = [number|null, RegExp|null, string];
|
||||
|
||||
const namedMatchers: { [key: string]: ErrorMatcher } = {
|
||||
noSourceCodeFound: [
|
||||
32,
|
||||
null,
|
||||
`No source code was seen during the build. Please see...
|
||||
https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build`
|
||||
],
|
||||
noSourceCodeFoundJavascript: [
|
||||
null,
|
||||
new RegExp("No JavaScript or TypeScript code found\\."),
|
||||
`No source code was seen during the build. Please see...
|
||||
https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/troubleshooting-code-scanning#no-code-found-during-the-build`
|
||||
]
|
||||
};
|
||||
|
||||
export const errorMatchers = Object.values(namedMatchers);
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
import * as exec from '@actions/exec';
|
||||
import test from 'ava';
|
||||
|
||||
import { exec_wrapper, ErrorMatcher } from './exec_wrapper';
|
||||
import { ErrorMatcher } from './error_matcher';
|
||||
import { exec_wrapper } from './exec_wrapper';
|
||||
import {setupTests} from './testing-utils';
|
||||
// import fs from 'fs';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import * as exec from '@actions/exec';
|
||||
import * as im from '@actions/exec/lib/interfaces';
|
||||
|
||||
|
||||
export type ErrorMatcher = [number, RegExp, string];
|
||||
import {ErrorMatcher} from './error_matcher';
|
||||
|
||||
/**
|
||||
* Wrapper for exec.exec which checks for specific return code and/or regex matches in console output.
|
||||
|
|
@ -64,7 +63,7 @@ export async function exec_wrapper(commandLine: string, args?: string[],
|
|||
|
||||
if (matchers) {
|
||||
for (const [customCode, regex, message] of matchers) {
|
||||
if (customCode === returnState || regex.test(stderr) || regex.test(stdout) ) {
|
||||
if (customCode === returnState || regex && (regex.test(stderr) || regex.test(stdout)) ) {
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue