Merge branch 'main' into aeisenberg/pack-in-inputs

This commit is contained in:
Andrew Eisenberg
2021-06-25 10:30:24 -07:00
committed by GitHub
20 changed files with 5670 additions and 47 deletions

View File

@@ -4,7 +4,9 @@ import * as configUtils from "./config-utils";
import { Logger } from "./logging";
function isInterpretedLanguage(language): boolean {
return language === "javascript" || language === "python";
return (
language === "javascript" || language === "python" || language === "ruby"
);
}
// Matches a string containing only characters that are legal to include in paths on windows.

View File

@@ -374,11 +374,11 @@ test("getExtraOptions throws for bad content", (t) => {
test("getCodeQLActionRepository", (t) => {
const logger = getRunnerLogger(true);
initializeEnvironment(Mode.actions, "1.2.3");
initializeEnvironment(Mode.runner, "1.2.3");
const repoActions = codeql.getCodeQLActionRepository(logger);
t.deepEqual(repoActions, "github/codeql-action");
initializeEnvironment(Mode.runner, "1.2.3");
initializeEnvironment(Mode.actions, "1.2.3");
// isRunningLocalAction() === true
delete process.env["GITHUB_ACTION_REPOSITORY"];

View File

@@ -39,6 +39,16 @@ interface ExtraOptions {
};
}
export class CommandInvocationError extends Error {
constructor(cmd: string, args: string[], exitCode: number, error: string) {
super(
`Failure invoking ${cmd} with arguments ${args}.\n
Exit code ${exitCode} and error was:\n
${error}`
);
}
}
export interface CodeQL {
/**
* Get the path of the CodeQL executable.
@@ -175,7 +185,7 @@ function getCodeQLBundleName(): string {
}
export function getCodeQLActionRepository(logger: Logger): string {
if (util.isActions()) {
if (!util.isActions()) {
return CODEQL_DEFAULT_ACTION_REPOSITORY;
} else {
return getActionsCodeQLActionRepository(logger);
@@ -884,14 +894,32 @@ export function getExtraOptions(
return all.concat(specific);
}
/*
* A constant defining the maximum number of characters we will keep from
* the programs stderr for logging. This serves two purposes:
* (1) It avoids an OOM if a program fails in a way that results it
* printing many log lines.
* (2) It avoids us hitting the limit of how much data we can send in our
* status reports on GitHub.com.
*/
const maxErrorSize = 20_000;
async function runTool(cmd: string, args: string[] = []) {
let output = "";
await new toolrunner.ToolRunner(cmd, args, {
let error = "";
const exitCode = await new toolrunner.ToolRunner(cmd, args, {
listeners: {
stdout: (data: Buffer) => {
output += data.toString();
},
stderr: (data: Buffer) => {
const toRead = Math.min(maxErrorSize - error.length, data.length);
error += data.toString("utf8", 0, toRead);
},
},
ignoreReturnCode: true,
}).exec();
if (exitCode !== 0)
throw new CommandInvocationError(cmd, args, exitCode, error);
return output;
}

View File

@@ -24,6 +24,20 @@ test("ensure lines of code works for cpp and js", async (t) => {
});
});
test("ensure lines of code works for csharp", async (t) => {
const results = await countLoc(
path.join(__dirname, "../tests/multi-language-repo"),
[],
[],
[Language.csharp],
getRunnerLogger(true)
);
t.deepEqual(results, {
csharp: 10,
});
});
test("ensure lines of code can handle undefined language", async (t) => {
const results = await countLoc(
path.join(__dirname, "../tests/multi-language-repo"),