mirror of
https://github.com/github/codeql-action.git
synced 2026-05-17 08:40:16 +00:00
WIP
This commit is contained in:
Generated
+34
-10
@@ -273,6 +273,7 @@ function resolveFunction(partialCodeql, methodName, defaultImplementation) {
|
||||
*/
|
||||
function setCodeQL(partialCodeql) {
|
||||
cachedCodeQL = {
|
||||
getVersion: resolveFunction(partialCodeql, "getVersion", () => Promise.resolve("0.0.0")),
|
||||
getPath: resolveFunction(partialCodeql, "getPath", () => "/tmp/dummy-path"),
|
||||
printVersion: resolveFunction(partialCodeql, "printVersion"),
|
||||
getTracerEnv: resolveFunction(partialCodeql, "getTracerEnv"),
|
||||
@@ -306,12 +307,28 @@ function getCachedCodeQL() {
|
||||
}
|
||||
exports.getCachedCodeQL = getCachedCodeQL;
|
||||
function getCodeQLForCmd(cmd) {
|
||||
let version;
|
||||
return {
|
||||
async getVersion() {
|
||||
if (!version) {
|
||||
await this.printVersion();
|
||||
}
|
||||
return version;
|
||||
},
|
||||
getPath() {
|
||||
return cmd;
|
||||
},
|
||||
async printVersion() {
|
||||
await runTool(cmd, ["version", "--format=json"]);
|
||||
const output = await runTool(cmd, ["version", "--format=json"]);
|
||||
try {
|
||||
version = JSON.parse(output).version;
|
||||
if (!version) {
|
||||
throw new Error("Missing version");
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(`Unexpected output from codeql version: ${e}`);
|
||||
}
|
||||
},
|
||||
async getTracerEnv(databasePath) {
|
||||
// Write tracer-env.js to a temp location.
|
||||
@@ -498,22 +515,22 @@ function getCodeQLForCmd(cmd) {
|
||||
* downloaded. The check to determine what the latest version is is done
|
||||
* each time this package is requested.
|
||||
*/
|
||||
async packDownload(packs) {
|
||||
async packDownload(packsOrSuites, extraSearchPath) {
|
||||
const codeqlArgs = [
|
||||
"pack",
|
||||
"download",
|
||||
"--format=json",
|
||||
...getExtraOptionsFromEnv(["pack", "download"]),
|
||||
...packs.map(packWithVersionToString),
|
||||
...packsOrSuites,
|
||||
];
|
||||
if (extraSearchPath) {
|
||||
codeqlArgs.push("--additional-packs", extraSearchPath);
|
||||
}
|
||||
const output = await runTool(cmd, codeqlArgs);
|
||||
try {
|
||||
const parsedOutput = JSON.parse(output);
|
||||
if (Array.isArray(parsedOutput.packs) &&
|
||||
// TODO PackDownloadOutput will not include the version if it is not specified
|
||||
// in the input. The version is always the latest version available.
|
||||
// It should be added to the output, but this requires a CLI change
|
||||
parsedOutput.packs.every((p) => p.name /* && p.version */)) {
|
||||
parsedOutput.packs.every((p) => p.name && p.version)) {
|
||||
return parsedOutput;
|
||||
}
|
||||
else {
|
||||
@@ -544,9 +561,6 @@ function getCodeQLForCmd(cmd) {
|
||||
},
|
||||
};
|
||||
}
|
||||
function packWithVersionToString(pack) {
|
||||
return pack.version ? `${pack.packName}@${pack.version}` : pack.packName;
|
||||
}
|
||||
/**
|
||||
* Gets the options for `path` of `options` as an array of extra option strings.
|
||||
*/
|
||||
@@ -593,6 +607,16 @@ function getExtraOptions(options, paths, pathInfo) {
|
||||
return all.concat(specific);
|
||||
}
|
||||
exports.getExtraOptions = getExtraOptions;
|
||||
// TODO verify that this is the correct version.
|
||||
const CODEQL_MIN_VERSION_DOWNLOAD_PACKS_FROM_SUITES = ">=2.6.0";
|
||||
/**
|
||||
* Determines if this codeql supports introspecting query suites to look for packages
|
||||
* to download.
|
||||
*/
|
||||
async function supportsDownloadPacksFromSuites(codeQL) {
|
||||
return semver.satisfies(await codeQL.getVersion(), CODEQL_MIN_VERSION_DOWNLOAD_PACKS_FROM_SUITES);
|
||||
}
|
||||
exports.supportsDownloadPacksFromSuites = supportsDownloadPacksFromSuites;
|
||||
/*
|
||||
* A constant defining the maximum number of characters we will keep from
|
||||
* the programs stderr for logging. This serves two purposes:
|
||||
|
||||
Reference in New Issue
Block a user