mirror of
https://github.com/github/codeql-action.git
synced 2026-05-07 22:30:44 +00:00
Call query compile during init
This commit is contained in:
Generated
+8
@@ -249,6 +249,7 @@ function setCodeQL(partialCodeql) {
|
||||
finalizeDatabase: resolveFunction(partialCodeql, "finalizeDatabase"),
|
||||
resolveQueries: resolveFunction(partialCodeql, "resolveQueries"),
|
||||
databaseAnalyze: resolveFunction(partialCodeql, "databaseAnalyze"),
|
||||
queryCompile: resolveFunction(partialCodeql, "queryCompile"),
|
||||
};
|
||||
return cachedCodeQL;
|
||||
}
|
||||
@@ -408,6 +409,13 @@ function getCodeQLForCmd(cmd) {
|
||||
querySuite,
|
||||
]).exec();
|
||||
},
|
||||
async queryCompile(querySuite) {
|
||||
await new toolrunner.ToolRunner(cmd, [
|
||||
"query",
|
||||
"compile",
|
||||
querySuite,
|
||||
]).exec();
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Generated
+34
@@ -7,6 +7,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const actionsUtil = __importStar(require("./actions-util"));
|
||||
const init_1 = require("./init");
|
||||
@@ -79,6 +80,9 @@ async function run() {
|
||||
codeql = initCodeQLResult.codeql;
|
||||
toolsVersion = initCodeQLResult.toolsVersion;
|
||||
config = await init_1.initConfig(actionsUtil.getOptionalInput("languages"), actionsUtil.getOptionalInput("queries"), actionsUtil.getOptionalInput("config-file"), repository_1.parseRepositoryNwo(actionsUtil.getRequiredEnvParam("GITHUB_REPOSITORY")), actionsUtil.getRequiredEnvParam("RUNNER_TEMP"), actionsUtil.getRequiredEnvParam("RUNNER_TOOL_CACHE"), codeql, actionsUtil.getRequiredEnvParam("GITHUB_WORKSPACE"), gitHubVersion, apiDetails, logger);
|
||||
// Compile queries and (TODO: extract query cache hash)
|
||||
// MG: Spell out what info we need from the config, and move to init.ts
|
||||
await compileQueries(codeql, config, logger);
|
||||
if (config.languages.includes(languages_1.Language.python) &&
|
||||
actionsUtil.getRequiredInput("setup-python-dependencies") === "true") {
|
||||
try {
|
||||
@@ -133,5 +137,35 @@ async function runWrapper() {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
async function compileQueries(codeql, config, logger) {
|
||||
// MG: This method is based of `runQueries`.
|
||||
// Creating the query suite file could be refactored out of that method.
|
||||
for (const language of config.languages) {
|
||||
logger.startGroup(`Analyzing ${language}`);
|
||||
const queries = config.queries[language];
|
||||
if (queries.builtin.length === 0 && queries.custom.length === 0) {
|
||||
throw new Error(`Unable to analyse ${language} as no queries were selected for this language`);
|
||||
}
|
||||
for (const type of ["custom"]) {
|
||||
// MG: Only compile custom, but we would be ok doing also builtin
|
||||
if (queries[type].length > 0) {
|
||||
// Pass the queries to codeql using a file instead of using the command
|
||||
// line to avoid command line length restrictions, particularly on windows.
|
||||
const querySuitePath = `${language}-queries-${type}.qls`;
|
||||
const querySuiteContents = queries[type]
|
||||
.map((q) => `- query: ${q}`)
|
||||
.join("\n");
|
||||
fs.writeFileSync(querySuitePath, querySuiteContents);
|
||||
logger.debug(`Query suite file for ${language}...\n${querySuiteContents}`);
|
||||
await codeql.queryCompile(querySuitePath);
|
||||
logger.debug(`Queries compiled`);
|
||||
logger.endGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Compute hash
|
||||
const hash = "abc";
|
||||
return hash;
|
||||
}
|
||||
void runWrapper();
|
||||
//# sourceMappingURL=init-action.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -93,6 +93,10 @@ export interface CodeQL {
|
||||
addSnippetsFlag: string,
|
||||
threadsFlag: string
|
||||
): Promise<void>;
|
||||
/**
|
||||
* Run 'codeql query compile'.
|
||||
*/
|
||||
queryCompile(querySuite: string): Promise<void>;
|
||||
}
|
||||
|
||||
export interface ResolveQueriesOutput {
|
||||
@@ -405,6 +409,7 @@ export function setCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
|
||||
finalizeDatabase: resolveFunction(partialCodeql, "finalizeDatabase"),
|
||||
resolveQueries: resolveFunction(partialCodeql, "resolveQueries"),
|
||||
databaseAnalyze: resolveFunction(partialCodeql, "databaseAnalyze"),
|
||||
queryCompile: resolveFunction(partialCodeql, "queryCompile"),
|
||||
};
|
||||
return cachedCodeQL;
|
||||
}
|
||||
@@ -613,6 +618,13 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
||||
querySuite,
|
||||
]).exec();
|
||||
},
|
||||
async queryCompile(querySuite: string) {
|
||||
await new toolrunner.ToolRunner(cmd, [
|
||||
"query",
|
||||
"compile",
|
||||
querySuite,
|
||||
]).exec();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+50
-1
@@ -1,3 +1,5 @@
|
||||
import * as fs from "fs";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as actionsUtil from "./actions-util";
|
||||
@@ -11,7 +13,7 @@ import {
|
||||
runInit,
|
||||
} from "./init";
|
||||
import { Language } from "./languages";
|
||||
import { getActionsLogger } from "./logging";
|
||||
import { getActionsLogger, Logger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import { checkGitHubVersionInRange, getGitHubVersion } from "./util";
|
||||
|
||||
@@ -158,6 +160,10 @@ async function run() {
|
||||
logger
|
||||
);
|
||||
|
||||
// Compile queries and (TODO: extract query cache hash)
|
||||
// MG: Spell out what info we need from the config, and move to init.ts
|
||||
await compileQueries(codeql, config, logger);
|
||||
|
||||
if (
|
||||
config.languages.includes(Language.python) &&
|
||||
actionsUtil.getRequiredInput("setup-python-dependencies") === "true"
|
||||
@@ -242,4 +248,47 @@ async function runWrapper() {
|
||||
}
|
||||
}
|
||||
|
||||
async function compileQueries(
|
||||
codeql: CodeQL,
|
||||
config: configUtils.Config,
|
||||
logger: Logger
|
||||
): Promise<string> {
|
||||
// MG: This method is based of `runQueries`.
|
||||
// Creating the query suite file could be refactored out of that method.
|
||||
for (const language of config.languages) {
|
||||
logger.startGroup(`Analyzing ${language}`);
|
||||
|
||||
const queries = config.queries[language];
|
||||
if (queries.builtin.length === 0 && queries.custom.length === 0) {
|
||||
throw new Error(
|
||||
`Unable to analyse ${language} as no queries were selected for this language`
|
||||
);
|
||||
}
|
||||
|
||||
for (const type of ["custom"]) {
|
||||
// MG: Only compile custom, but we would be ok doing also builtin
|
||||
if (queries[type].length > 0) {
|
||||
// Pass the queries to codeql using a file instead of using the command
|
||||
// line to avoid command line length restrictions, particularly on windows.
|
||||
const querySuitePath = `${language}-queries-${type}.qls`;
|
||||
const querySuiteContents = queries[type]
|
||||
.map((q: string) => `- query: ${q}`)
|
||||
.join("\n");
|
||||
fs.writeFileSync(querySuitePath, querySuiteContents);
|
||||
logger.debug(
|
||||
`Query suite file for ${language}...\n${querySuiteContents}`
|
||||
);
|
||||
|
||||
await codeql.queryCompile(querySuitePath);
|
||||
|
||||
logger.debug(`Queries compiled`);
|
||||
logger.endGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Compute hash
|
||||
const hash = "abc";
|
||||
return hash;
|
||||
}
|
||||
|
||||
void runWrapper();
|
||||
|
||||
Reference in New Issue
Block a user