Remove CliConfigFileEnabled feature flag
This commit is contained in:
Родитель
216127f34a
Коммит
fa98ec0c7a
|
@ -134,7 +134,6 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
|||
const statusReport = {};
|
||||
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
|
||||
const queryFlags = [memoryFlag, threadsFlag];
|
||||
await (0, feature_flags_1.logCodeScanningConfigInCli)(codeql, features, logger);
|
||||
for (const language of config.languages) {
|
||||
const queries = config.queries[language];
|
||||
const queryFilters = validateQueryFilters(config.originalUserInput["query-filters"]);
|
||||
|
@ -143,7 +142,9 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
|||
const sarifFile = path.join(sarifFolder, `${language}.sarif`);
|
||||
let startTimeInterpretResults;
|
||||
let endTimeInterpretResults;
|
||||
if (await (0, feature_flags_1.useCodeScanningConfigInCli)(codeql, features)) {
|
||||
// TODO: will clean up in a future commit
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
if (true) {
|
||||
// If we are using the code scanning config in the CLI,
|
||||
// much of the work needed to generate the query suites
|
||||
// is done in the CLI. We just need to make a single
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const ava_1 = __importDefault(require("ava"));
|
||||
const yaml = __importStar(require("js-yaml"));
|
||||
const sinon = __importStar(require("sinon"));
|
||||
const analyze_1 = require("./analyze");
|
||||
const codeql_1 = require("./codeql");
|
||||
|
@ -131,86 +130,19 @@ const util = __importStar(require("./util"));
|
|||
fs.mkdirSync(util.getCodeQLDatabasePath(config, language), {
|
||||
recursive: true,
|
||||
});
|
||||
config.queries[language] = {
|
||||
builtin: ["foo.ql"],
|
||||
custom: [],
|
||||
};
|
||||
const builtinStatusReport = await (0, analyze_1.runQueries)(tmpDir, memoryFlag, addSnippetsFlag, threadsFlag, undefined, config, (0, logging_1.getRunnerLogger)(true), (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.QaTelemetryEnabled]));
|
||||
const hasPacks = language in packs;
|
||||
const statusReportKeys = Object.keys(builtinStatusReport).sort();
|
||||
if (hasPacks) {
|
||||
t.deepEqual(statusReportKeys.length, 4, statusReportKeys.toString());
|
||||
t.deepEqual(statusReportKeys[0], `analyze_builtin_queries_${language}_duration_ms`);
|
||||
t.deepEqual(statusReportKeys[1], `analyze_custom_queries_${language}_duration_ms`);
|
||||
t.deepEqual(statusReportKeys[2], "event_reports");
|
||||
t.deepEqual(statusReportKeys[3], `interpret_results_${language}_duration_ms`);
|
||||
}
|
||||
else {
|
||||
t.deepEqual(statusReportKeys[0], `analyze_builtin_queries_${language}_duration_ms`);
|
||||
t.deepEqual(statusReportKeys[1], "event_reports");
|
||||
t.deepEqual(statusReportKeys[2], `interpret_results_${language}_duration_ms`);
|
||||
}
|
||||
if (builtinStatusReport.event_reports) {
|
||||
for (const eventReport of builtinStatusReport.event_reports) {
|
||||
t.deepEqual(eventReport.event, "codeql database interpret-results");
|
||||
t.true("properties" in eventReport);
|
||||
t.true("alertCounts" in eventReport.properties);
|
||||
}
|
||||
}
|
||||
config.queries[language] = {
|
||||
builtin: [],
|
||||
custom: [
|
||||
{
|
||||
queries: ["foo.ql"],
|
||||
searchPath: "/1",
|
||||
},
|
||||
{
|
||||
queries: ["bar.ql"],
|
||||
searchPath: "/2",
|
||||
},
|
||||
],
|
||||
};
|
||||
const customStatusReport = await (0, analyze_1.runQueries)(tmpDir, memoryFlag, addSnippetsFlag, threadsFlag, undefined, config, (0, logging_1.getRunnerLogger)(true), (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.QaTelemetryEnabled]));
|
||||
t.deepEqual(Object.keys(customStatusReport).length, 3);
|
||||
t.true(`analyze_custom_queries_${language}_duration_ms` in customStatusReport);
|
||||
const expectedSearchPathsUsed = hasPacks
|
||||
? [undefined, undefined, "/1", "/2", undefined]
|
||||
: [undefined, "/1", "/2"];
|
||||
t.deepEqual(searchPathsUsed, expectedSearchPathsUsed);
|
||||
t.true(`interpret_results_${language}_duration_ms` in customStatusReport);
|
||||
t.true("event_reports" in customStatusReport);
|
||||
if (customStatusReport.event_reports) {
|
||||
for (const eventReport of customStatusReport.event_reports) {
|
||||
t.deepEqual(eventReport.event, "codeql database interpret-results");
|
||||
t.true("properties" in eventReport);
|
||||
t.true("alertCounts" in eventReport.properties);
|
||||
}
|
||||
t.deepEqual(Object.keys(builtinStatusReport).sort(), [
|
||||
`analyze_builtin_queries_${language}_duration_ms`,
|
||||
"event_reports",
|
||||
`interpret_results_${language}_duration_ms`,
|
||||
]);
|
||||
for (const eventReport of builtinStatusReport.event_reports) {
|
||||
t.deepEqual(eventReport.event, "codeql database interpret-results");
|
||||
t.true("properties" in eventReport);
|
||||
t.true("alertCounts" in eventReport.properties);
|
||||
}
|
||||
}
|
||||
verifyQuerySuites(tmpDir);
|
||||
});
|
||||
function verifyQuerySuites(tmpDir) {
|
||||
const qlsContent = [
|
||||
{
|
||||
query: "foo.ql",
|
||||
},
|
||||
];
|
||||
const qlsContent2 = [
|
||||
{
|
||||
query: "bar.ql",
|
||||
},
|
||||
];
|
||||
for (const lang of Object.values(languages_1.Language)) {
|
||||
t.deepEqual(readContents(`${lang}-queries-builtin.qls`), qlsContent);
|
||||
t.deepEqual(readContents(`${lang}-queries-custom-0.qls`), qlsContent);
|
||||
t.deepEqual(readContents(`${lang}-queries-custom-1.qls`), qlsContent2);
|
||||
}
|
||||
function readContents(name) {
|
||||
const x = fs.readFileSync(path.join(tmpDir, "codeql_databases", name), "utf8");
|
||||
console.log(x);
|
||||
return yaml.load(fs.readFileSync(path.join(tmpDir, "codeql_databases", name), "utf8"));
|
||||
}
|
||||
}
|
||||
});
|
||||
function mockCodeQL() {
|
||||
return {
|
||||
|
@ -245,12 +177,6 @@ function createBaseConfig(tmpDir) {
|
|||
trapCacheDownloadTime: 0,
|
||||
};
|
||||
}
|
||||
function createQueryConfig(builtin, custom) {
|
||||
return {
|
||||
builtin,
|
||||
custom: custom.map((c) => ({ searchPath: "/search", queries: [c] })),
|
||||
};
|
||||
}
|
||||
async function runQueriesWithConfig(config, features) {
|
||||
for (const language of config.languages) {
|
||||
fs.mkdirSync(util.getCodeQLDatabasePath(config, language), {
|
||||
|
@ -268,7 +194,6 @@ function getDatabaseRunQueriesCalls(mock) {
|
|||
(0, codeql_1.setCodeQL)(codeql);
|
||||
const config = createBaseConfig(tmpDir);
|
||||
config.languages = [languages_1.Language.cpp];
|
||||
config.queries.cpp = createQueryConfig(["foo.ql"], []);
|
||||
await runQueriesWithConfig(config, []);
|
||||
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [true]);
|
||||
});
|
||||
|
@ -279,58 +204,10 @@ function getDatabaseRunQueriesCalls(mock) {
|
|||
(0, codeql_1.setCodeQL)(codeql);
|
||||
const config = createBaseConfig(tmpDir);
|
||||
config.languages = [languages_1.Language.cpp, languages_1.Language.java];
|
||||
config.queries.cpp = createQueryConfig(["foo.ql"], []);
|
||||
config.queries.java = createQueryConfig(["bar.ql"], []);
|
||||
await runQueriesWithConfig(config, []);
|
||||
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [true, true]);
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("optimizeForLastQueryRun for two languages, with custom queries", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const codeql = mockCodeQL();
|
||||
(0, codeql_1.setCodeQL)(codeql);
|
||||
const config = createBaseConfig(tmpDir);
|
||||
config.languages = [languages_1.Language.cpp, languages_1.Language.java];
|
||||
config.queries.cpp = createQueryConfig(["foo.ql"], ["c1.ql", "c2.ql"]);
|
||||
config.queries.java = createQueryConfig(["bar.ql"], ["c3.ql"]);
|
||||
await runQueriesWithConfig(config, []);
|
||||
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [false, false, true, false, true]);
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("optimizeForLastQueryRun for two languages, with custom queries and packs", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const codeql = mockCodeQL();
|
||||
(0, codeql_1.setCodeQL)(codeql);
|
||||
const config = createBaseConfig(tmpDir);
|
||||
config.languages = [languages_1.Language.cpp, languages_1.Language.java];
|
||||
config.queries.cpp = createQueryConfig(["foo.ql"], ["c1.ql", "c2.ql"]);
|
||||
config.queries.java = createQueryConfig(["bar.ql"], ["c3.ql"]);
|
||||
config.packs.cpp = ["a/cpp-pack1@0.1.0"];
|
||||
config.packs.java = ["b/java-pack1@0.2.0", "b/java-pack2@0.3.3"];
|
||||
await runQueriesWithConfig(config, []);
|
||||
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [false, false, false, true, false, false, true]);
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("optimizeForLastQueryRun for one language, CliConfigFileEnabled", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const codeql = mockCodeQL();
|
||||
(0, codeql_1.setCodeQL)(codeql);
|
||||
const config = createBaseConfig(tmpDir);
|
||||
config.languages = [languages_1.Language.cpp];
|
||||
await runQueriesWithConfig(config, [feature_flags_1.Feature.CliConfigFileEnabled]);
|
||||
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [true]);
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("optimizeForLastQueryRun for two languages, CliConfigFileEnabled", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const codeql = mockCodeQL();
|
||||
(0, codeql_1.setCodeQL)(codeql);
|
||||
const config = createBaseConfig(tmpDir);
|
||||
config.languages = [languages_1.Language.cpp, languages_1.Language.java];
|
||||
await runQueriesWithConfig(config, [feature_flags_1.Feature.CliConfigFileEnabled]);
|
||||
t.deepEqual(getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]), [true, true]);
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("validateQueryFilters", (t) => {
|
||||
t.notThrows(() => (0, analyze_1.validateQueryFilters)([]));
|
||||
t.notThrows(() => (0, analyze_1.validateQueryFilters)(undefined));
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -279,23 +279,18 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
|||
async printVersion() {
|
||||
await runTool(cmd, ["version", "--format=json"]);
|
||||
},
|
||||
async databaseInitCluster(config, sourceRoot, processName, features, qlconfigFile, logger) {
|
||||
async databaseInitCluster(config, sourceRoot, processName, qlconfigFile, logger) {
|
||||
const extraArgs = config.languages.map((language) => `--language=${language}`);
|
||||
if (config.languages.filter((l) => (0, languages_1.isTracedLanguage)(l)).length > 0) {
|
||||
extraArgs.push("--begin-tracing");
|
||||
extraArgs.push(...(await getTrapCachingExtractorConfigArgs(config)));
|
||||
extraArgs.push(`--trace-process-name=${processName}`);
|
||||
}
|
||||
// A code scanning config file is only generated if the CliConfigFileEnabled feature flag is enabled.
|
||||
const codeScanningConfigFile = await generateCodeScanningConfig(codeql, config, features, logger);
|
||||
// Only pass external repository token if a config file is going to be parsed by the CLI.
|
||||
let externalRepositoryToken;
|
||||
if (codeScanningConfigFile) {
|
||||
externalRepositoryToken = (0, actions_util_1.getOptionalInput)("external-repository-token");
|
||||
extraArgs.push(`--codescanning-config=${codeScanningConfigFile}`);
|
||||
if (externalRepositoryToken) {
|
||||
extraArgs.push("--external-repository-token-stdin");
|
||||
}
|
||||
const codeScanningConfigFile = await generateCodeScanningConfig(config, logger);
|
||||
const externalRepositoryToken = (0, actions_util_1.getOptionalInput)("external-repository-token");
|
||||
extraArgs.push(`--codescanning-config=${codeScanningConfigFile}`);
|
||||
if (externalRepositoryToken) {
|
||||
extraArgs.push("--external-repository-token-stdin");
|
||||
}
|
||||
if (qlconfigFile !== undefined &&
|
||||
(await util.codeQlVersionAbove(this, exports.CODEQL_VERSION_INIT_WITH_QLCONFIG))) {
|
||||
|
@ -862,17 +857,13 @@ function ensureEndsInPeriod(text) {
|
|||
return text[text.length - 1] === "." ? text : `${text}.`;
|
||||
}
|
||||
/**
|
||||
* If appropriate, generates a code scanning configuration that is to be used for a scan.
|
||||
* If the configuration is not to be generated, returns undefined.
|
||||
* Generates a code scanning configuration that is to be used for a scan.
|
||||
*
|
||||
* @param codeql The CodeQL object to use.
|
||||
* @param config The configuration to use.
|
||||
* @returns the path to the generated user configuration file.
|
||||
*/
|
||||
async function generateCodeScanningConfig(codeql, config, features, logger) {
|
||||
if (!(await (0, feature_flags_1.useCodeScanningConfigInCli)(codeql, features))) {
|
||||
return;
|
||||
}
|
||||
async function generateCodeScanningConfig(config, logger) {
|
||||
const codeScanningConfigFile = getGeneratedCodeScanningConfigPath(config);
|
||||
// make a copy so we can modify it
|
||||
const augmentedConfig = cloneObject(config.originalUserInput);
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -40,7 +40,6 @@ const sinon = __importStar(require("sinon"));
|
|||
const actionsUtil = __importStar(require("./actions-util"));
|
||||
const codeql = __importStar(require("./codeql"));
|
||||
const defaults = __importStar(require("./defaults.json"));
|
||||
const feature_flags_1 = require("./feature-flags");
|
||||
const languages_1 = require("./languages");
|
||||
const logging_1 = require("./logging");
|
||||
const setup_codeql_1 = require("./setup-codeql");
|
||||
|
@ -373,45 +372,20 @@ for (const isBundleVersionInUrl of [true, false]) {
|
|||
t.throws(() => codeql.getExtraOptions({ foo: 87 }, ["foo"], []));
|
||||
t.throws(() => codeql.getExtraOptions({ "*": [42], foo: { "*": 87, bar: [99] } }, ["foo", "bar"], []));
|
||||
});
|
||||
(0, ava_1.default)("databaseInitCluster() without injected codescanning config", async (t) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionInfo)("2.10.5"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
const thisStubConfig = {
|
||||
...stubConfig,
|
||||
tempDir,
|
||||
augmentationProperties: {
|
||||
queriesInputCombines: false,
|
||||
packsInputCombines: false,
|
||||
},
|
||||
};
|
||||
await codeqlObject.databaseInitCluster(thisStubConfig, "", undefined, (0, testing_utils_1.createFeatures)([]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should NOT have used an config file
|
||||
const configArg = args.find((arg) => arg.startsWith("--codescanning-config="));
|
||||
t.falsy(configArg, "Should NOT have injected a codescanning config");
|
||||
});
|
||||
});
|
||||
// Test macro for ensuring different variants of injected augmented configurations
|
||||
const injectedConfigMacro = ava_1.default.macro({
|
||||
exec: async (t, augmentationProperties, configOverride, expectedConfig) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves((0, testing_utils_1.makeVersionInfo)(feature_flags_1.featureConfig[feature_flags_1.Feature.CliConfigFileEnabled].minimumVersion ||
|
||||
"1.0.0"));
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionInfo)("1.0.0"));
|
||||
const thisStubConfig = {
|
||||
...stubConfig,
|
||||
...configOverride,
|
||||
tempDir,
|
||||
augmentationProperties,
|
||||
};
|
||||
await codeqlObject.databaseInitCluster(thisStubConfig, "", undefined, (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.CliConfigFileEnabled]), undefined, (0, logging_1.getRunnerLogger)(true));
|
||||
await codeqlObject.databaseInitCluster(thisStubConfig, "", undefined, undefined, (0, logging_1.getRunnerLogger)(true));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should have used an config file
|
||||
const configArg = args.find((arg) => arg.startsWith("--codescanning-config="));
|
||||
|
@ -542,30 +516,14 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
queries: [],
|
||||
},
|
||||
}, {});
|
||||
(0, ava_1.default)("does not pass a code scanning config or qlconfig file to the CLI when CLI config passing is disabled", async (t) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
// stubbed version doesn't matter. It just needs to be valid semver.
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionInfo)("0.0.0"));
|
||||
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, (0, testing_utils_1.createFeatures)([]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should not have used a config file
|
||||
const hasConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
||||
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
|
||||
// should not have passed a qlconfig file
|
||||
const hasQlconfigArg = args.some((arg) => arg.startsWith("--qlconfig-file="));
|
||||
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("passes a code scanning config AND qlconfig to the CLI when CLI config passing is enabled", async (t) => {
|
||||
(0, ava_1.default)("passes a code scanning config AND qlconfig to the CLI", async (t) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves((0, testing_utils_1.makeVersionInfo)(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
|
||||
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.CliConfigFileEnabled]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should have used a config file
|
||||
const hasCodeScanningConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
||||
|
@ -575,12 +533,12 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
t.truthy(hasQlconfigArg, "Should have injected a codescanning config");
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI config passing is enabled", async (t) => {
|
||||
(0, ava_1.default)("passes a code scanning config BUT NOT a qlconfig to the CLI for CodeQL v2.12.2", async (t) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves((0, testing_utils_1.makeVersionInfo)("2.12.2"));
|
||||
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.CliConfigFileEnabled]), "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, "/path/to/qlconfig.yml", (0, logging_1.getRunnerLogger)(true));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should have used a config file
|
||||
const hasCodeScanningConfigArg = args.some((arg) => arg.startsWith("--codescanning-config="));
|
||||
|
@ -597,7 +555,7 @@ const injectedConfigMacro = ava_1.default.macro({
|
|||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves((0, testing_utils_1.makeVersionInfo)(codeql.CODEQL_VERSION_INIT_WITH_QLCONFIG));
|
||||
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, (0, testing_utils_1.createFeatures)([feature_flags_1.Feature.CliConfigFileEnabled]), undefined, // undefined qlconfigFile
|
||||
await codeqlObject.databaseInitCluster({ ...stubConfig, tempDir }, "", undefined, undefined, // undefined qlconfigFile
|
||||
(0, logging_1.getRunnerLogger)(true));
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
const hasQlconfigArg = args.some((arg) => arg.startsWith("--qlconfig-file="));
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -31,8 +31,6 @@ const yaml = __importStar(require("js-yaml"));
|
|||
const semver = __importStar(require("semver"));
|
||||
const api = __importStar(require("./api-client"));
|
||||
const codeql_1 = require("./codeql");
|
||||
const externalQueries = __importStar(require("./external-queries"));
|
||||
const feature_flags_1 = require("./feature-flags");
|
||||
const languages_1 = require("./languages");
|
||||
const trap_caching_1 = require("./trap-caching");
|
||||
const util_1 = require("./util");
|
||||
|
@ -173,34 +171,6 @@ async function addLocalQueries(codeQL, resultMap, localQueryPath, workspacePath,
|
|||
const extraSearchPath = workspacePath;
|
||||
await runResolveQueries(codeQL, resultMap, [absoluteQueryPath], extraSearchPath);
|
||||
}
|
||||
/**
|
||||
* Retrieve the set of queries at the referenced remote repo and add them to resultMap.
|
||||
*/
|
||||
async function addRemoteQueries(codeQL, resultMap, queryUses, tempDir, apiDetails, logger, configFile) {
|
||||
let tok = queryUses.split("@");
|
||||
if (tok.length !== 2) {
|
||||
throw new util_1.UserError(getQueryUsesInvalid(configFile, queryUses));
|
||||
}
|
||||
const ref = tok[1];
|
||||
tok = tok[0].split("/");
|
||||
// The first token is the owner
|
||||
// The second token is the repo
|
||||
// The rest is a path, if there is more than one token combine them to form the full path
|
||||
if (tok.length < 2) {
|
||||
throw new util_1.UserError(getQueryUsesInvalid(configFile, queryUses));
|
||||
}
|
||||
// Check none of the parts of the repository name are empty
|
||||
if (tok[0].trim() === "" || tok[1].trim() === "") {
|
||||
throw new util_1.UserError(getQueryUsesInvalid(configFile, queryUses));
|
||||
}
|
||||
const nwo = `${tok[0]}/${tok[1]}`;
|
||||
// Checkout the external repository
|
||||
const checkoutPath = await externalQueries.checkoutExternalRepository(nwo, ref, apiDetails, tempDir, logger);
|
||||
const queryPath = tok.length > 2
|
||||
? path.join(checkoutPath, tok.slice(2).join("/"))
|
||||
: checkoutPath;
|
||||
await runResolveQueries(codeQL, resultMap, [queryPath], checkoutPath);
|
||||
}
|
||||
/**
|
||||
* Parse a query 'uses' field to a discrete set of query files and update resultMap.
|
||||
*
|
||||
|
@ -209,7 +179,9 @@ async function addRemoteQueries(codeQL, resultMap, queryUses, tempDir, apiDetail
|
|||
* local paths starting with './', or references to remote repos, or
|
||||
* a finite set of hardcoded terms for builtin suites.
|
||||
*/
|
||||
async function parseQueryUses(languages, codeQL, resultMap, queryUses, tempDir, workspacePath, apiDetails, features, logger, configFile) {
|
||||
async function parseQueryUses(languages, codeQL, resultMap, queryUses,
|
||||
// TODO: will clean this up in a future commit
|
||||
_tempDir, workspacePath, _apiDetails, _features, _logger, configFile) {
|
||||
queryUses = queryUses.trim();
|
||||
if (queryUses === "") {
|
||||
throw new util_1.UserError(getQueryUsesInvalid(configFile));
|
||||
|
@ -224,12 +196,6 @@ async function parseQueryUses(languages, codeQL, resultMap, queryUses, tempDir,
|
|||
await addBuiltinSuiteQueries(languages, codeQL, resultMap, queryUses, configFile);
|
||||
return;
|
||||
}
|
||||
// Otherwise, must be a reference to another repo.
|
||||
// If config parsing is handled in CLI, then this repo will be downloaded
|
||||
// later by the CLI.
|
||||
if (!(await (0, feature_flags_1.useCodeScanningConfigInCli)(codeQL, features))) {
|
||||
await addRemoteQueries(codeQL, resultMap, queryUses, tempDir, apiDetails, logger, configFile);
|
||||
}
|
||||
}
|
||||
// Regex validating stars in paths or paths-ignore entries.
|
||||
// The intention is to only allow ** to appear when immediately
|
||||
|
@ -908,7 +874,9 @@ function dbLocationOrDefault(dbLocation, tempDir) {
|
|||
* This will parse the config from the user input if present, or generate
|
||||
* a default config. The parsed config is then stored to a known location.
|
||||
*/
|
||||
async function initConfig(languagesInput, queriesInput, packsInput, registriesInput, configFile, dbLocation, configInput, trapCachingEnabled, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, codeQL, workspacePath, gitHubVersion, apiDetails, features, logger) {
|
||||
async function initConfig(languagesInput, queriesInput, packsInput,
|
||||
// TODO: will clean this up in a future commit
|
||||
_registriesInput, configFile, dbLocation, configInput, trapCachingEnabled, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, codeQL, workspacePath, gitHubVersion, apiDetails, features, logger) {
|
||||
let config;
|
||||
// if configInput is set, it takes precedence over configFile
|
||||
if (configInput) {
|
||||
|
@ -927,25 +895,6 @@ async function initConfig(languagesInput, queriesInput, packsInput, registriesIn
|
|||
else {
|
||||
config = await loadConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, trapCachingEnabled, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, codeQL, workspacePath, gitHubVersion, apiDetails, features, logger);
|
||||
}
|
||||
// When using the codescanning config in the CLI, pack downloads
|
||||
// happen in the CLI during the `database init` command, so no need
|
||||
// to download them here.
|
||||
await (0, feature_flags_1.logCodeScanningConfigInCli)(codeQL, features, logger);
|
||||
if (!(await (0, feature_flags_1.useCodeScanningConfigInCli)(codeQL, features))) {
|
||||
// The list of queries should not be empty for any language. If it is then
|
||||
// it is a user configuration error.
|
||||
// This check occurs in the CLI when it parses the config file.
|
||||
for (const language of config.languages) {
|
||||
const hasBuiltinQueries = config.queries[language]?.builtin.length > 0;
|
||||
const hasCustomQueries = config.queries[language]?.custom.length > 0;
|
||||
const hasPacks = (config.packs[language]?.length || 0) > 0;
|
||||
if (!hasPacks && !hasBuiltinQueries && !hasCustomQueries) {
|
||||
throw new util_1.UserError(`Did not detect any queries to run for ${language}. ` +
|
||||
"Please make sure that the default queries are enabled, or you are specifying queries to run.");
|
||||
}
|
||||
}
|
||||
await downloadPacks(codeQL, config.languages, config.packs, apiDetails, registriesInput, config.tempDir, logger);
|
||||
}
|
||||
// Save the config so we can easily access it again in the future
|
||||
await saveConfig(config, logger);
|
||||
return config;
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -585,35 +585,6 @@ function queriesToResolvedQueryForm(queries) {
|
|||
t.true(config.queries["javascript"].custom[0].queries[0].endsWith(`${path.sep}foo`));
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("Invalid queries in workflow file handled correctly", async (t) => {
|
||||
return await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
const queries = "foo/bar@v1@v3";
|
||||
const languages = "javascript";
|
||||
// This function just needs to be type-correct; it doesn't need to do anything,
|
||||
// since we're deliberately passing in invalid data
|
||||
const codeQL = (0, codeql_1.setCodeQL)({
|
||||
async resolveQueries() {
|
||||
return {
|
||||
byLanguage: {
|
||||
javascript: {},
|
||||
},
|
||||
noDeclaredLanguage: {},
|
||||
multipleDeclaredLanguages: {},
|
||||
};
|
||||
},
|
||||
async packDownload() {
|
||||
return { packs: [] };
|
||||
},
|
||||
});
|
||||
try {
|
||||
await configUtils.initConfig(languages, queries, undefined, undefined, undefined, undefined, undefined, false, false, "", "", { owner: "github", repo: "example" }, tmpDir, codeQL, tmpDir, gitHubVersion, sampleApiDetails, (0, testing_utils_1.createFeatures)([]), (0, logging_1.getRunnerLogger)(true));
|
||||
t.fail("initConfig did not throw error");
|
||||
}
|
||||
catch (err) {
|
||||
t.deepEqual(err, new util_1.UserError(configUtils.getQueryUsesInvalid(undefined, "foo/bar@v1@v3")));
|
||||
}
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("API client used when reading remote config", async (t) => {
|
||||
return await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
const codeQL = (0, codeql_1.setCodeQL)({
|
||||
|
@ -856,10 +827,6 @@ function doInvalidQueryUsesTest(input, expectedErrorMessageGenerator) {
|
|||
}
|
||||
// Various "uses" fields, and the errors they should produce
|
||||
doInvalidQueryUsesTest("''", (c) => configUtils.getQueryUsesInvalid(c, undefined));
|
||||
doInvalidQueryUsesTest("foo/bar", (c) => configUtils.getQueryUsesInvalid(c, "foo/bar"));
|
||||
doInvalidQueryUsesTest("foo/bar@v1@v2", (c) => configUtils.getQueryUsesInvalid(c, "foo/bar@v1@v2"));
|
||||
doInvalidQueryUsesTest("foo@master", (c) => configUtils.getQueryUsesInvalid(c, "foo@master"));
|
||||
doInvalidQueryUsesTest("https://github.com/foo/bar@master", (c) => configUtils.getQueryUsesInvalid(c, "https://github.com/foo/bar@master"));
|
||||
doInvalidQueryUsesTest("./foo", (c) => configUtils.getLocalPathDoesNotExist(c, "foo"));
|
||||
doInvalidQueryUsesTest("./..", (c) => configUtils.getLocalPathOutsideOfRepository(c, ".."));
|
||||
const validPaths = [
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.logCodeScanningConfigInCli = exports.useCodeScanningConfigInCli = exports.Features = exports.FEATURE_FLAGS_FILE_NAME = exports.featureConfig = exports.Feature = exports.CODEQL_VERSION_FINE_GRAINED_PARALLELISM = exports.CODEQL_VERSION_BUNDLE_SEMANTICALLY_VERSIONED = void 0;
|
||||
exports.Features = exports.FEATURE_FLAGS_FILE_NAME = exports.featureConfig = exports.Feature = exports.CODEQL_VERSION_FINE_GRAINED_PARALLELISM = exports.CODEQL_VERSION_BUNDLE_SEMANTICALLY_VERSIONED = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const semver = __importStar(require("semver"));
|
||||
|
@ -48,7 +48,6 @@ exports.CODEQL_VERSION_FINE_GRAINED_PARALLELISM = "2.15.1";
|
|||
*/
|
||||
var Feature;
|
||||
(function (Feature) {
|
||||
Feature["CliConfigFileEnabled"] = "cli_config_file_enabled";
|
||||
Feature["CodeqlJavaLombokEnabled"] = "codeql_java_lombok_enabled";
|
||||
Feature["CppDependencyInstallation"] = "cpp_dependency_installation_enabled";
|
||||
Feature["DisableKotlinAnalysisEnabled"] = "disable_kotlin_analysis_enabled";
|
||||
|
@ -73,11 +72,6 @@ exports.featureConfig = {
|
|||
minimumVersion: undefined,
|
||||
defaultValue: false,
|
||||
},
|
||||
[Feature.CliConfigFileEnabled]: {
|
||||
envVar: "CODEQL_PASS_CONFIG_TO_CLI",
|
||||
minimumVersion: undefined,
|
||||
defaultValue: true,
|
||||
},
|
||||
[Feature.EvaluatorFineGrainedParallelismEnabled]: {
|
||||
envVar: "CODEQL_EVALUATOR_FINE_GRAINED_PARALLELISM",
|
||||
minimumVersion: exports.CODEQL_VERSION_FINE_GRAINED_PARALLELISM,
|
||||
|
@ -332,21 +326,4 @@ class GitHubFeatureFlags {
|
|||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @returns Whether the Action should generate a code scanning config file
|
||||
* that gets passed to the CLI.
|
||||
*/
|
||||
async function useCodeScanningConfigInCli(codeql, features) {
|
||||
return await features.getValue(Feature.CliConfigFileEnabled, codeql);
|
||||
}
|
||||
exports.useCodeScanningConfigInCli = useCodeScanningConfigInCli;
|
||||
async function logCodeScanningConfigInCli(codeql, features, logger) {
|
||||
if (await useCodeScanningConfigInCli(codeql, features)) {
|
||||
logger.info("Code Scanning configuration file being processed in the codeql CLI.");
|
||||
}
|
||||
else {
|
||||
logger.info("Code Scanning configuration file being processed in the codeql-action.");
|
||||
}
|
||||
}
|
||||
exports.logCodeScanningConfigInCli = logCodeScanningConfigInCli;
|
||||
//# sourceMappingURL=feature-flags.js.map
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -192,16 +192,16 @@ for (const feature of Object.keys(feature_flags_1.featureConfig)) {
|
|||
(0, testing_utils_1.mockFeatureFlagApiEndpoint)(200, expectedFeatureEnablement);
|
||||
const cachedFeatureFlags = path.join(tmpDir, feature_flags_1.FEATURE_FLAGS_FILE_NAME);
|
||||
t.false(fs.existsSync(cachedFeatureFlags), "Feature flag cached file should not exist before getting feature flags");
|
||||
t.true(await features.getValue(feature_flags_1.Feature.CliConfigFileEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.CliConfigFileEnabled)), "Feature flag should be enabled initially");
|
||||
t.true(await features.getValue(feature_flags_1.Feature.QaTelemetryEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.QaTelemetryEnabled)), "Feature flag should be enabled initially");
|
||||
t.true(fs.existsSync(cachedFeatureFlags), "Feature flag cached file should exist after getting feature flags");
|
||||
const actualFeatureEnablement = JSON.parse(fs.readFileSync(cachedFeatureFlags, "utf8"));
|
||||
t.deepEqual(actualFeatureEnablement, expectedFeatureEnablement);
|
||||
// now test that we actually use the feature flag cache instead of the server
|
||||
actualFeatureEnablement[feature_flags_1.Feature.CliConfigFileEnabled] = false;
|
||||
actualFeatureEnablement[feature_flags_1.Feature.QaTelemetryEnabled] = false;
|
||||
fs.writeFileSync(cachedFeatureFlags, JSON.stringify(actualFeatureEnablement));
|
||||
// delete the in memory cache so that we are forced to use the cached file
|
||||
features.gitHubFeatureFlags.cachedApiResponse = undefined;
|
||||
t.false(await features.getValue(feature_flags_1.Feature.CliConfigFileEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.CliConfigFileEnabled)), "Feature flag should be enabled after reading from cached file");
|
||||
t.false(await features.getValue(feature_flags_1.Feature.QaTelemetryEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.QaTelemetryEnabled)), "Feature flag should be enabled after reading from cached file");
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("Environment variable can override feature flag cache", async (t) => {
|
||||
|
@ -210,10 +210,10 @@ for (const feature of Object.keys(feature_flags_1.featureConfig)) {
|
|||
const expectedFeatureEnablement = initializeFeatures(true);
|
||||
(0, testing_utils_1.mockFeatureFlagApiEndpoint)(200, expectedFeatureEnablement);
|
||||
const cachedFeatureFlags = path.join(tmpDir, feature_flags_1.FEATURE_FLAGS_FILE_NAME);
|
||||
t.true(await features.getValue(feature_flags_1.Feature.CliConfigFileEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.CliConfigFileEnabled)), "Feature flag should be enabled initially");
|
||||
t.true(await features.getValue(feature_flags_1.Feature.QaTelemetryEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.QaTelemetryEnabled)), "Feature flag should be enabled initially");
|
||||
t.true(fs.existsSync(cachedFeatureFlags), "Feature flag cached file should exist after getting feature flags");
|
||||
process.env.CODEQL_PASS_CONFIG_TO_CLI = "false";
|
||||
t.false(await features.getValue(feature_flags_1.Feature.CliConfigFileEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.CliConfigFileEnabled)), "Feature flag should be disabled after setting env var");
|
||||
process.env.CODEQL_ACTION_QA_TELEMETRY = "false";
|
||||
t.false(await features.getValue(feature_flags_1.Feature.QaTelemetryEnabled, includeCodeQlIfRequired(feature_flags_1.Feature.QaTelemetryEnabled)), "Feature flag should be disabled after setting env var");
|
||||
});
|
||||
});
|
||||
for (const variant of [util_1.GitHubVariant.GHAE, util_1.GitHubVariant.GHES]) {
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -250,7 +250,7 @@ async function run() {
|
|||
core.exportVariable("CODEQL_EXTRACTOR_PYTHON_DISABLE_LIBRARY_EXTRACTION", "true");
|
||||
}
|
||||
const sourceRoot = path.resolve((0, util_1.getRequiredEnvParam)("GITHUB_WORKSPACE"), (0, actions_util_1.getOptionalInput)("source-root") || "");
|
||||
const tracerConfig = await (0, init_1.runInit)(codeql, config, sourceRoot, "Runner.Worker.exe", registriesInput, features, apiDetails, logger);
|
||||
const tracerConfig = await (0, init_1.runInit)(codeql, config, sourceRoot, "Runner.Worker.exe", registriesInput, apiDetails, logger);
|
||||
if (tracerConfig !== undefined) {
|
||||
for (const [key, value] of Object.entries(tracerConfig.env)) {
|
||||
core.exportVariable(key, value);
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -31,7 +31,6 @@ const safeWhich = __importStar(require("@chrisgavin/safe-which"));
|
|||
const analysisPaths = __importStar(require("./analysis-paths"));
|
||||
const codeql_1 = require("./codeql");
|
||||
const configUtils = __importStar(require("./config-utils"));
|
||||
const feature_flags_1 = require("./feature-flags");
|
||||
const languages_1 = require("./languages");
|
||||
const tracer_config_1 = require("./tracer-config");
|
||||
const util = __importStar(require("./util"));
|
||||
|
@ -51,25 +50,16 @@ async function initConfig(languagesInput, queriesInput, packsInput, registriesIn
|
|||
return config;
|
||||
}
|
||||
exports.initConfig = initConfig;
|
||||
async function runInit(codeql, config, sourceRoot, processName, registriesInput, features, apiDetails, logger) {
|
||||
async function runInit(codeql, config, sourceRoot, processName, registriesInput, apiDetails, logger) {
|
||||
fs.mkdirSync(config.dbLocation, { recursive: true });
|
||||
try {
|
||||
// When parsing the codeql config in the CLI, we have not yet created the qlconfig file.
|
||||
// So, create it now.
|
||||
// If we are parsing the config file in the Action, then the qlconfig file was already created
|
||||
// before the `pack download` command was invoked. It is not required for the init command.
|
||||
let registriesAuthTokens;
|
||||
let qlconfigFile;
|
||||
if (await (0, feature_flags_1.useCodeScanningConfigInCli)(codeql, features)) {
|
||||
({ registriesAuthTokens, qlconfigFile } =
|
||||
await configUtils.generateRegistries(registriesInput, config.tempDir, logger));
|
||||
}
|
||||
const { registriesAuthTokens, qlconfigFile } = await configUtils.generateRegistries(registriesInput, config.tempDir, logger);
|
||||
await configUtils.wrapEnvironment({
|
||||
GITHUB_TOKEN: apiDetails.auth,
|
||||
CODEQL_REGISTRIES_AUTH: registriesAuthTokens,
|
||||
},
|
||||
// Init a database cluster
|
||||
async () => await codeql.databaseInitCluster(config, sourceRoot, processName, features, qlconfigFile, logger));
|
||||
async () => await codeql.databaseInitCluster(config, sourceRoot, processName, qlconfigFile, logger));
|
||||
}
|
||||
catch (e) {
|
||||
throw processError(e);
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";;;;;;;;;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,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC;gBAChC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;aAC/B,CAAC,CAAC,IAAI,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CACZ,gFAAgF,CAAC,IAAI;YACnF,qGAAqG;YACrG,oGAAoG;YACpG,iDAAiD,CACpD,CAAC;QACF,OAAO;IACT,CAAC;IACD,MAAM,CAAC,QAAQ,EAAE,CAAC;AACpB,CAAC;AAzCD,8CAyCC"}
|
|
@ -2,7 +2,6 @@ import * as fs from "fs";
|
|||
import * as path from "path";
|
||||
|
||||
import test, { ExecutionContext } from "ava";
|
||||
import * as yaml from "js-yaml";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import {
|
||||
|
@ -13,7 +12,7 @@ import {
|
|||
QueriesStatusReport,
|
||||
} from "./analyze";
|
||||
import { CodeQL, setCodeQL } from "./codeql";
|
||||
import { Config, QueriesWithSearchPath } from "./config-utils";
|
||||
import { Config } from "./config-utils";
|
||||
import { Feature } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
|
@ -134,10 +133,6 @@ test("status report fields and search path setting", async (t) => {
|
|||
recursive: true,
|
||||
});
|
||||
|
||||
config.queries[language] = {
|
||||
builtin: ["foo.ql"],
|
||||
custom: [],
|
||||
};
|
||||
const builtinStatusReport = await runQueries(
|
||||
tmpDir,
|
||||
memoryFlag,
|
||||
|
@ -148,116 +143,18 @@ test("status report fields and search path setting", async (t) => {
|
|||
getRunnerLogger(true),
|
||||
createFeatures([Feature.QaTelemetryEnabled]),
|
||||
);
|
||||
const hasPacks = language in packs;
|
||||
const statusReportKeys = Object.keys(builtinStatusReport).sort();
|
||||
if (hasPacks) {
|
||||
t.deepEqual(statusReportKeys.length, 4, statusReportKeys.toString());
|
||||
t.deepEqual(
|
||||
statusReportKeys[0],
|
||||
`analyze_builtin_queries_${language}_duration_ms`,
|
||||
);
|
||||
t.deepEqual(
|
||||
statusReportKeys[1],
|
||||
`analyze_custom_queries_${language}_duration_ms`,
|
||||
);
|
||||
t.deepEqual(statusReportKeys[2], "event_reports");
|
||||
t.deepEqual(
|
||||
statusReportKeys[3],
|
||||
`interpret_results_${language}_duration_ms`,
|
||||
);
|
||||
} else {
|
||||
t.deepEqual(
|
||||
statusReportKeys[0],
|
||||
`analyze_builtin_queries_${language}_duration_ms`,
|
||||
);
|
||||
t.deepEqual(statusReportKeys[1], "event_reports");
|
||||
t.deepEqual(
|
||||
statusReportKeys[2],
|
||||
`interpret_results_${language}_duration_ms`,
|
||||
);
|
||||
}
|
||||
if (builtinStatusReport.event_reports) {
|
||||
for (const eventReport of builtinStatusReport.event_reports) {
|
||||
t.deepEqual(eventReport.event, "codeql database interpret-results");
|
||||
t.true("properties" in eventReport);
|
||||
t.true("alertCounts" in eventReport.properties!);
|
||||
}
|
||||
}
|
||||
|
||||
config.queries[language] = {
|
||||
builtin: [],
|
||||
custom: [
|
||||
{
|
||||
queries: ["foo.ql"],
|
||||
searchPath: "/1",
|
||||
},
|
||||
{
|
||||
queries: ["bar.ql"],
|
||||
searchPath: "/2",
|
||||
},
|
||||
],
|
||||
};
|
||||
const customStatusReport = await runQueries(
|
||||
tmpDir,
|
||||
memoryFlag,
|
||||
addSnippetsFlag,
|
||||
threadsFlag,
|
||||
undefined,
|
||||
config,
|
||||
getRunnerLogger(true),
|
||||
createFeatures([Feature.QaTelemetryEnabled]),
|
||||
);
|
||||
t.deepEqual(Object.keys(customStatusReport).length, 3);
|
||||
t.true(
|
||||
`analyze_custom_queries_${language}_duration_ms` in customStatusReport,
|
||||
);
|
||||
const expectedSearchPathsUsed = hasPacks
|
||||
? [undefined, undefined, "/1", "/2", undefined]
|
||||
: [undefined, "/1", "/2"];
|
||||
t.deepEqual(searchPathsUsed, expectedSearchPathsUsed);
|
||||
t.true(`interpret_results_${language}_duration_ms` in customStatusReport);
|
||||
t.true("event_reports" in customStatusReport);
|
||||
if (customStatusReport.event_reports) {
|
||||
for (const eventReport of customStatusReport.event_reports) {
|
||||
t.deepEqual(eventReport.event, "codeql database interpret-results");
|
||||
t.true("properties" in eventReport);
|
||||
t.true("alertCounts" in eventReport.properties!);
|
||||
}
|
||||
t.deepEqual(Object.keys(builtinStatusReport).sort(), [
|
||||
`analyze_builtin_queries_${language}_duration_ms`,
|
||||
"event_reports",
|
||||
`interpret_results_${language}_duration_ms`,
|
||||
]);
|
||||
for (const eventReport of builtinStatusReport.event_reports!) {
|
||||
t.deepEqual(eventReport.event, "codeql database interpret-results");
|
||||
t.true("properties" in eventReport);
|
||||
t.true("alertCounts" in eventReport.properties!);
|
||||
}
|
||||
}
|
||||
|
||||
verifyQuerySuites(tmpDir);
|
||||
});
|
||||
|
||||
function verifyQuerySuites(tmpDir: string) {
|
||||
const qlsContent = [
|
||||
{
|
||||
query: "foo.ql",
|
||||
},
|
||||
];
|
||||
const qlsContent2 = [
|
||||
{
|
||||
query: "bar.ql",
|
||||
},
|
||||
];
|
||||
for (const lang of Object.values(Language)) {
|
||||
t.deepEqual(readContents(`${lang}-queries-builtin.qls`), qlsContent);
|
||||
t.deepEqual(readContents(`${lang}-queries-custom-0.qls`), qlsContent);
|
||||
t.deepEqual(readContents(`${lang}-queries-custom-1.qls`), qlsContent2);
|
||||
}
|
||||
|
||||
function readContents(name: string) {
|
||||
const x = fs.readFileSync(
|
||||
path.join(tmpDir, "codeql_databases", name),
|
||||
"utf8",
|
||||
);
|
||||
console.log(x);
|
||||
|
||||
return yaml.load(
|
||||
fs.readFileSync(path.join(tmpDir, "codeql_databases", name), "utf8"),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function mockCodeQL(): Partial<CodeQL> {
|
||||
|
@ -295,16 +192,6 @@ function createBaseConfig(tmpDir: string): Config {
|
|||
};
|
||||
}
|
||||
|
||||
function createQueryConfig(
|
||||
builtin: string[],
|
||||
custom: string[],
|
||||
): { builtin: string[]; custom: QueriesWithSearchPath[] } {
|
||||
return {
|
||||
builtin,
|
||||
custom: custom.map((c) => ({ searchPath: "/search", queries: [c] })),
|
||||
};
|
||||
}
|
||||
|
||||
async function runQueriesWithConfig(
|
||||
config: Config,
|
||||
features: Feature[],
|
||||
|
@ -336,7 +223,6 @@ test("optimizeForLastQueryRun for one language", async (t) => {
|
|||
setCodeQL(codeql);
|
||||
const config: Config = createBaseConfig(tmpDir);
|
||||
config.languages = [Language.cpp];
|
||||
config.queries.cpp = createQueryConfig(["foo.ql"], []);
|
||||
|
||||
await runQueriesWithConfig(config, []);
|
||||
t.deepEqual(
|
||||
|
@ -352,8 +238,6 @@ test("optimizeForLastQueryRun for two languages", async (t) => {
|
|||
setCodeQL(codeql);
|
||||
const config: Config = createBaseConfig(tmpDir);
|
||||
config.languages = [Language.cpp, Language.java];
|
||||
config.queries.cpp = createQueryConfig(["foo.ql"], []);
|
||||
config.queries.java = createQueryConfig(["bar.ql"], []);
|
||||
|
||||
await runQueriesWithConfig(config, []);
|
||||
t.deepEqual(
|
||||
|
@ -363,71 +247,6 @@ test("optimizeForLastQueryRun for two languages", async (t) => {
|
|||
});
|
||||
});
|
||||
|
||||
test("optimizeForLastQueryRun for two languages, with custom queries", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const codeql = mockCodeQL();
|
||||
setCodeQL(codeql);
|
||||
const config: Config = createBaseConfig(tmpDir);
|
||||
config.languages = [Language.cpp, Language.java];
|
||||
config.queries.cpp = createQueryConfig(["foo.ql"], ["c1.ql", "c2.ql"]);
|
||||
config.queries.java = createQueryConfig(["bar.ql"], ["c3.ql"]);
|
||||
|
||||
await runQueriesWithConfig(config, []);
|
||||
t.deepEqual(
|
||||
getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]),
|
||||
[false, false, true, false, true],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("optimizeForLastQueryRun for two languages, with custom queries and packs", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const codeql = mockCodeQL();
|
||||
setCodeQL(codeql);
|
||||
const config: Config = createBaseConfig(tmpDir);
|
||||
config.languages = [Language.cpp, Language.java];
|
||||
config.queries.cpp = createQueryConfig(["foo.ql"], ["c1.ql", "c2.ql"]);
|
||||
config.queries.java = createQueryConfig(["bar.ql"], ["c3.ql"]);
|
||||
config.packs.cpp = ["a/cpp-pack1@0.1.0"];
|
||||
config.packs.java = ["b/java-pack1@0.2.0", "b/java-pack2@0.3.3"];
|
||||
await runQueriesWithConfig(config, []);
|
||||
t.deepEqual(
|
||||
getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]),
|
||||
[false, false, false, true, false, false, true],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("optimizeForLastQueryRun for one language, CliConfigFileEnabled", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const codeql = mockCodeQL();
|
||||
setCodeQL(codeql);
|
||||
const config: Config = createBaseConfig(tmpDir);
|
||||
config.languages = [Language.cpp];
|
||||
|
||||
await runQueriesWithConfig(config, [Feature.CliConfigFileEnabled]);
|
||||
t.deepEqual(
|
||||
getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]),
|
||||
[true],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("optimizeForLastQueryRun for two languages, CliConfigFileEnabled", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const codeql = mockCodeQL();
|
||||
setCodeQL(codeql);
|
||||
const config: Config = createBaseConfig(tmpDir);
|
||||
config.languages = [Language.cpp, Language.java];
|
||||
|
||||
await runQueriesWithConfig(config, [Feature.CliConfigFileEnabled]);
|
||||
t.deepEqual(
|
||||
getDatabaseRunQueriesCalls(codeql).map((c) => c.args[4]),
|
||||
[true, true],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("validateQueryFilters", (t) => {
|
||||
t.notThrows(() => validateQueryFilters([]));
|
||||
t.notThrows(() => validateQueryFilters(undefined));
|
||||
|
|
|
@ -13,12 +13,7 @@ import {
|
|||
getCodeQL,
|
||||
} from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import {
|
||||
FeatureEnablement,
|
||||
Feature,
|
||||
logCodeScanningConfigInCli,
|
||||
useCodeScanningConfigInCli,
|
||||
} from "./feature-flags";
|
||||
import { FeatureEnablement, Feature } from "./feature-flags";
|
||||
import { isScannedLanguage, Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { DatabaseCreationTimings, EventReport } from "./status-report";
|
||||
|
@ -245,8 +240,6 @@ export async function runQueries(
|
|||
const codeql = await getCodeQL(config.codeQLCmd);
|
||||
const queryFlags = [memoryFlag, threadsFlag];
|
||||
|
||||
await logCodeScanningConfigInCli(codeql, features, logger);
|
||||
|
||||
for (const language of config.languages) {
|
||||
const queries = config.queries[language];
|
||||
const queryFilters = validateQueryFilters(
|
||||
|
@ -258,7 +251,9 @@ export async function runQueries(
|
|||
const sarifFile = path.join(sarifFolder, `${language}.sarif`);
|
||||
let startTimeInterpretResults: Date;
|
||||
let endTimeInterpretResults: Date;
|
||||
if (await useCodeScanningConfigInCli(codeql, features)) {
|
||||
// TODO: will clean up in a future commit
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
if (true) {
|
||||
// If we are using the code scanning config in the CLI,
|
||||
// much of the work needed to generate the query suites
|
||||
// is done in the CLI. We just need to make a single
|
||||
|
|
|
@ -16,7 +16,6 @@ import { GitHubApiDetails } from "./api-client";
|
|||
import * as codeql from "./codeql";
|
||||
import { AugmentationProperties, Config } from "./config-utils";
|
||||
import * as defaults from "./defaults.json";
|
||||
import { Feature, featureConfig } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { ToolsSource } from "./setup-codeql";
|
||||
|
@ -560,41 +559,6 @@ test("getExtraOptions throws for bad content", (t) => {
|
|||
);
|
||||
});
|
||||
|
||||
test("databaseInitCluster() without injected codescanning config", async (t) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.10.5"));
|
||||
// safeWhich throws because of the test CodeQL object.
|
||||
sinon.stub(safeWhich, "safeWhich").resolves("");
|
||||
|
||||
const thisStubConfig: Config = {
|
||||
...stubConfig,
|
||||
tempDir,
|
||||
augmentationProperties: {
|
||||
queriesInputCombines: false,
|
||||
packsInputCombines: false,
|
||||
},
|
||||
};
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
thisStubConfig,
|
||||
"",
|
||||
undefined,
|
||||
createFeatures([]),
|
||||
"/path/to/qlconfig.yml",
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should NOT have used an config file
|
||||
const configArg = args.find((arg: string) =>
|
||||
arg.startsWith("--codescanning-config="),
|
||||
);
|
||||
t.falsy(configArg, "Should NOT have injected a codescanning config");
|
||||
});
|
||||
});
|
||||
|
||||
// Test macro for ensuring different variants of injected augmented configurations
|
||||
const injectedConfigMacro = test.macro({
|
||||
exec: async (
|
||||
|
@ -606,14 +570,7 @@ const injectedConfigMacro = test.macro({
|
|||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
sinon
|
||||
.stub(codeqlObject, "getVersion")
|
||||
.resolves(
|
||||
makeVersionInfo(
|
||||
featureConfig[Feature.CliConfigFileEnabled].minimumVersion ||
|
||||
"1.0.0",
|
||||
),
|
||||
);
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("1.0.0"));
|
||||
|
||||
const thisStubConfig: Config = {
|
||||
...stubConfig,
|
||||
|
@ -626,7 +583,6 @@ const injectedConfigMacro = test.macro({
|
|||
thisStubConfig,
|
||||
"",
|
||||
undefined,
|
||||
createFeatures([Feature.CliConfigFileEnabled]),
|
||||
undefined,
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
@ -830,38 +786,7 @@ test(
|
|||
{},
|
||||
);
|
||||
|
||||
test("does not pass a code scanning config or qlconfig file to the CLI when CLI config passing is disabled", async (t: ExecutionContext<unknown>) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
// stubbed version doesn't matter. It just needs to be valid semver.
|
||||
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("0.0.0"));
|
||||
|
||||
await codeqlObject.databaseInitCluster(
|
||||
{ ...stubConfig, tempDir },
|
||||
"",
|
||||
undefined,
|
||||
createFeatures([]),
|
||||
"/path/to/qlconfig.yml",
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
||||
const args = runnerConstructorStub.firstCall.args[1];
|
||||
// should not have used a config file
|
||||
const hasConfigArg = args.some((arg: string) =>
|
||||
arg.startsWith("--codescanning-config="),
|
||||
);
|
||||
t.false(hasConfigArg, "Should NOT have injected a codescanning config");
|
||||
|
||||
// should not have passed a qlconfig file
|
||||
const hasQlconfigArg = args.some((arg: string) =>
|
||||
arg.startsWith("--qlconfig-file="),
|
||||
);
|
||||
t.false(hasQlconfigArg, "Should NOT have passed a qlconfig file");
|
||||
});
|
||||
});
|
||||
|
||||
test("passes a code scanning config AND qlconfig to the CLI when CLI config passing is enabled", async (t: ExecutionContext<unknown>) => {
|
||||
test("passes a code scanning config AND qlconfig to the CLI", async (t: ExecutionContext<unknown>) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
|
@ -873,7 +798,6 @@ test("passes a code scanning config AND qlconfig to the CLI when CLI config pass
|
|||
{ ...stubConfig, tempDir },
|
||||
"",
|
||||
undefined,
|
||||
createFeatures([Feature.CliConfigFileEnabled]),
|
||||
"/path/to/qlconfig.yml",
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
@ -893,7 +817,7 @@ test("passes a code scanning config AND qlconfig to the CLI when CLI config pass
|
|||
});
|
||||
});
|
||||
|
||||
test("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI config passing is enabled", async (t: ExecutionContext<unknown>) => {
|
||||
test("passes a code scanning config BUT NOT a qlconfig to the CLI for CodeQL v2.12.2", async (t: ExecutionContext<unknown>) => {
|
||||
await util.withTmpDir(async (tempDir) => {
|
||||
const runnerConstructorStub = stubToolRunnerConstructor();
|
||||
const codeqlObject = await codeql.getCodeQLForTesting();
|
||||
|
@ -903,7 +827,6 @@ test("passes a code scanning config BUT NOT a qlconfig to the CLI when CLI confi
|
|||
{ ...stubConfig, tempDir },
|
||||
"",
|
||||
undefined,
|
||||
createFeatures([Feature.CliConfigFileEnabled]),
|
||||
"/path/to/qlconfig.yml",
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
@ -938,7 +861,6 @@ test("does not pass a qlconfig to the CLI when it is undefined", async (t: Execu
|
|||
{ ...stubConfig, tempDir },
|
||||
"",
|
||||
undefined,
|
||||
createFeatures([Feature.CliConfigFileEnabled]),
|
||||
undefined, // undefined qlconfigFile
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
|
|
|
@ -19,7 +19,6 @@ import {
|
|||
CodeQLDefaultVersionInfo,
|
||||
Feature,
|
||||
FeatureEnablement,
|
||||
useCodeScanningConfigInCli,
|
||||
} from "./feature-flags";
|
||||
import { isTracedLanguage, Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
|
@ -98,7 +97,6 @@ export interface CodeQL {
|
|||
config: Config,
|
||||
sourceRoot: string,
|
||||
processName: string | undefined,
|
||||
features: FeatureEnablement,
|
||||
qlconfigFile: string | undefined,
|
||||
logger: Logger,
|
||||
): Promise<void>;
|
||||
|
@ -576,7 +574,6 @@ export async function getCodeQLForCmd(
|
|||
config: Config,
|
||||
sourceRoot: string,
|
||||
processName: string | undefined,
|
||||
features: FeatureEnablement,
|
||||
qlconfigFile: string | undefined,
|
||||
logger: Logger,
|
||||
) {
|
||||
|
@ -589,21 +586,16 @@ export async function getCodeQLForCmd(
|
|||
extraArgs.push(`--trace-process-name=${processName}`);
|
||||
}
|
||||
|
||||
// A code scanning config file is only generated if the CliConfigFileEnabled feature flag is enabled.
|
||||
const codeScanningConfigFile = await generateCodeScanningConfig(
|
||||
codeql,
|
||||
config,
|
||||
features,
|
||||
logger,
|
||||
);
|
||||
// Only pass external repository token if a config file is going to be parsed by the CLI.
|
||||
let externalRepositoryToken: string | undefined;
|
||||
if (codeScanningConfigFile) {
|
||||
externalRepositoryToken = getOptionalInput("external-repository-token");
|
||||
extraArgs.push(`--codescanning-config=${codeScanningConfigFile}`);
|
||||
if (externalRepositoryToken) {
|
||||
extraArgs.push("--external-repository-token-stdin");
|
||||
}
|
||||
const externalRepositoryToken = getOptionalInput(
|
||||
"external-repository-token",
|
||||
);
|
||||
extraArgs.push(`--codescanning-config=${codeScanningConfigFile}`);
|
||||
if (externalRepositoryToken) {
|
||||
extraArgs.push("--external-repository-token-stdin");
|
||||
}
|
||||
|
||||
if (
|
||||
|
@ -1325,22 +1317,16 @@ function ensureEndsInPeriod(text: string): string {
|
|||
}
|
||||
|
||||
/**
|
||||
* If appropriate, generates a code scanning configuration that is to be used for a scan.
|
||||
* If the configuration is not to be generated, returns undefined.
|
||||
* Generates a code scanning configuration that is to be used for a scan.
|
||||
*
|
||||
* @param codeql The CodeQL object to use.
|
||||
* @param config The configuration to use.
|
||||
* @returns the path to the generated user configuration file.
|
||||
*/
|
||||
async function generateCodeScanningConfig(
|
||||
codeql: CodeQL,
|
||||
config: Config,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
): Promise<string | undefined> {
|
||||
if (!(await useCodeScanningConfigInCli(codeql, features))) {
|
||||
return;
|
||||
}
|
||||
): Promise<string> {
|
||||
const codeScanningConfigFile = getGeneratedCodeScanningConfigPath(config);
|
||||
|
||||
// make a copy so we can modify it
|
||||
|
|
|
@ -1101,62 +1101,6 @@ test("Using config input and file together, config input should be used.", async
|
|||
});
|
||||
});
|
||||
|
||||
test("Invalid queries in workflow file handled correctly", async (t) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const queries = "foo/bar@v1@v3";
|
||||
const languages = "javascript";
|
||||
|
||||
// This function just needs to be type-correct; it doesn't need to do anything,
|
||||
// since we're deliberately passing in invalid data
|
||||
const codeQL = setCodeQL({
|
||||
async resolveQueries() {
|
||||
return {
|
||||
byLanguage: {
|
||||
javascript: {},
|
||||
},
|
||||
noDeclaredLanguage: {},
|
||||
multipleDeclaredLanguages: {},
|
||||
};
|
||||
},
|
||||
async packDownload(): Promise<PackDownloadOutput> {
|
||||
return { packs: [] };
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
await configUtils.initConfig(
|
||||
languages,
|
||||
queries,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example" },
|
||||
tmpDir,
|
||||
codeQL,
|
||||
tmpDir,
|
||||
gitHubVersion,
|
||||
sampleApiDetails,
|
||||
createFeatures([]),
|
||||
getRunnerLogger(true),
|
||||
);
|
||||
t.fail("initConfig did not throw error");
|
||||
} catch (err) {
|
||||
t.deepEqual(
|
||||
err,
|
||||
new UserError(
|
||||
configUtils.getQueryUsesInvalid(undefined, "foo/bar@v1@v3"),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("API client used when reading remote config", async (t) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const codeQL = setCodeQL({
|
||||
|
@ -1643,18 +1587,6 @@ function doInvalidQueryUsesTest(
|
|||
doInvalidQueryUsesTest("''", (c) =>
|
||||
configUtils.getQueryUsesInvalid(c, undefined),
|
||||
);
|
||||
doInvalidQueryUsesTest("foo/bar", (c) =>
|
||||
configUtils.getQueryUsesInvalid(c, "foo/bar"),
|
||||
);
|
||||
doInvalidQueryUsesTest("foo/bar@v1@v2", (c) =>
|
||||
configUtils.getQueryUsesInvalid(c, "foo/bar@v1@v2"),
|
||||
);
|
||||
doInvalidQueryUsesTest("foo@master", (c) =>
|
||||
configUtils.getQueryUsesInvalid(c, "foo@master"),
|
||||
);
|
||||
doInvalidQueryUsesTest("https://github.com/foo/bar@master", (c) =>
|
||||
configUtils.getQueryUsesInvalid(c, "https://github.com/foo/bar@master"),
|
||||
);
|
||||
doInvalidQueryUsesTest("./foo", (c) =>
|
||||
configUtils.getLocalPathDoesNotExist(c, "foo"),
|
||||
);
|
||||
|
|
|
@ -12,12 +12,7 @@ import {
|
|||
CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE,
|
||||
ResolveQueriesOutput,
|
||||
} from "./codeql";
|
||||
import * as externalQueries from "./external-queries";
|
||||
import {
|
||||
FeatureEnablement,
|
||||
logCodeScanningConfigInCli,
|
||||
useCodeScanningConfigInCli,
|
||||
} from "./feature-flags";
|
||||
import { FeatureEnablement } from "./feature-flags";
|
||||
import { Language, parseLanguage } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
|
@ -454,55 +449,6 @@ async function addLocalQueries(
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the set of queries at the referenced remote repo and add them to resultMap.
|
||||
*/
|
||||
async function addRemoteQueries(
|
||||
codeQL: CodeQL,
|
||||
resultMap: Queries,
|
||||
queryUses: string,
|
||||
tempDir: string,
|
||||
apiDetails: api.GitHubApiExternalRepoDetails,
|
||||
logger: Logger,
|
||||
configFile?: string,
|
||||
) {
|
||||
let tok = queryUses.split("@");
|
||||
if (tok.length !== 2) {
|
||||
throw new UserError(getQueryUsesInvalid(configFile, queryUses));
|
||||
}
|
||||
|
||||
const ref = tok[1];
|
||||
|
||||
tok = tok[0].split("/");
|
||||
// The first token is the owner
|
||||
// The second token is the repo
|
||||
// The rest is a path, if there is more than one token combine them to form the full path
|
||||
if (tok.length < 2) {
|
||||
throw new UserError(getQueryUsesInvalid(configFile, queryUses));
|
||||
}
|
||||
// Check none of the parts of the repository name are empty
|
||||
if (tok[0].trim() === "" || tok[1].trim() === "") {
|
||||
throw new UserError(getQueryUsesInvalid(configFile, queryUses));
|
||||
}
|
||||
const nwo = `${tok[0]}/${tok[1]}`;
|
||||
|
||||
// Checkout the external repository
|
||||
const checkoutPath = await externalQueries.checkoutExternalRepository(
|
||||
nwo,
|
||||
ref,
|
||||
apiDetails,
|
||||
tempDir,
|
||||
logger,
|
||||
);
|
||||
|
||||
const queryPath =
|
||||
tok.length > 2
|
||||
? path.join(checkoutPath, tok.slice(2).join("/"))
|
||||
: checkoutPath;
|
||||
|
||||
await runResolveQueries(codeQL, resultMap, [queryPath], checkoutPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a query 'uses' field to a discrete set of query files and update resultMap.
|
||||
*
|
||||
|
@ -516,11 +462,12 @@ async function parseQueryUses(
|
|||
codeQL: CodeQL,
|
||||
resultMap: Queries,
|
||||
queryUses: string,
|
||||
tempDir: string,
|
||||
// TODO: will clean this up in a future commit
|
||||
_tempDir: string,
|
||||
workspacePath: string,
|
||||
apiDetails: api.GitHubApiExternalRepoDetails,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
_apiDetails: api.GitHubApiExternalRepoDetails,
|
||||
_features: FeatureEnablement,
|
||||
_logger: Logger,
|
||||
configFile?: string,
|
||||
): Promise<void> {
|
||||
queryUses = queryUses.trim();
|
||||
|
@ -551,21 +498,6 @@ async function parseQueryUses(
|
|||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, must be a reference to another repo.
|
||||
// If config parsing is handled in CLI, then this repo will be downloaded
|
||||
// later by the CLI.
|
||||
if (!(await useCodeScanningConfigInCli(codeQL, features))) {
|
||||
await addRemoteQueries(
|
||||
codeQL,
|
||||
resultMap,
|
||||
queryUses,
|
||||
tempDir,
|
||||
apiDetails,
|
||||
logger,
|
||||
configFile,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Regex validating stars in paths or paths-ignore entries.
|
||||
|
@ -1647,7 +1579,8 @@ export async function initConfig(
|
|||
languagesInput: string | undefined,
|
||||
queriesInput: string | undefined,
|
||||
packsInput: string | undefined,
|
||||
registriesInput: string | undefined,
|
||||
// TODO: will clean this up in a future commit
|
||||
_registriesInput: string | undefined,
|
||||
configFile: string | undefined,
|
||||
dbLocation: string | undefined,
|
||||
configInput: string | undefined,
|
||||
|
@ -1721,38 +1654,6 @@ export async function initConfig(
|
|||
);
|
||||
}
|
||||
|
||||
// When using the codescanning config in the CLI, pack downloads
|
||||
// happen in the CLI during the `database init` command, so no need
|
||||
// to download them here.
|
||||
await logCodeScanningConfigInCli(codeQL, features, logger);
|
||||
|
||||
if (!(await useCodeScanningConfigInCli(codeQL, features))) {
|
||||
// The list of queries should not be empty for any language. If it is then
|
||||
// it is a user configuration error.
|
||||
// This check occurs in the CLI when it parses the config file.
|
||||
for (const language of config.languages) {
|
||||
const hasBuiltinQueries = config.queries[language]?.builtin.length > 0;
|
||||
const hasCustomQueries = config.queries[language]?.custom.length > 0;
|
||||
const hasPacks = (config.packs[language]?.length || 0) > 0;
|
||||
if (!hasPacks && !hasBuiltinQueries && !hasCustomQueries) {
|
||||
throw new UserError(
|
||||
`Did not detect any queries to run for ${language}. ` +
|
||||
"Please make sure that the default queries are enabled, or you are specifying queries to run.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await downloadPacks(
|
||||
codeQL,
|
||||
config.languages,
|
||||
config.packs,
|
||||
apiDetails,
|
||||
registriesInput,
|
||||
config.tempDir,
|
||||
logger,
|
||||
);
|
||||
}
|
||||
|
||||
// Save the config so we can easily access it again in the future
|
||||
await saveConfig(config, logger);
|
||||
return config;
|
||||
|
|
|
@ -291,8 +291,8 @@ test("Feature flags are saved to disk", async (t) => {
|
|||
|
||||
t.true(
|
||||
await features.getValue(
|
||||
Feature.CliConfigFileEnabled,
|
||||
includeCodeQlIfRequired(Feature.CliConfigFileEnabled),
|
||||
Feature.QaTelemetryEnabled,
|
||||
includeCodeQlIfRequired(Feature.QaTelemetryEnabled),
|
||||
),
|
||||
"Feature flag should be enabled initially",
|
||||
);
|
||||
|
@ -308,7 +308,7 @@ test("Feature flags are saved to disk", async (t) => {
|
|||
t.deepEqual(actualFeatureEnablement, expectedFeatureEnablement);
|
||||
|
||||
// now test that we actually use the feature flag cache instead of the server
|
||||
actualFeatureEnablement[Feature.CliConfigFileEnabled] = false;
|
||||
actualFeatureEnablement[Feature.QaTelemetryEnabled] = false;
|
||||
fs.writeFileSync(
|
||||
cachedFeatureFlags,
|
||||
JSON.stringify(actualFeatureEnablement),
|
||||
|
@ -319,8 +319,8 @@ test("Feature flags are saved to disk", async (t) => {
|
|||
|
||||
t.false(
|
||||
await features.getValue(
|
||||
Feature.CliConfigFileEnabled,
|
||||
includeCodeQlIfRequired(Feature.CliConfigFileEnabled),
|
||||
Feature.QaTelemetryEnabled,
|
||||
includeCodeQlIfRequired(Feature.QaTelemetryEnabled),
|
||||
),
|
||||
"Feature flag should be enabled after reading from cached file",
|
||||
);
|
||||
|
@ -336,8 +336,8 @@ test("Environment variable can override feature flag cache", async (t) => {
|
|||
const cachedFeatureFlags = path.join(tmpDir, FEATURE_FLAGS_FILE_NAME);
|
||||
t.true(
|
||||
await features.getValue(
|
||||
Feature.CliConfigFileEnabled,
|
||||
includeCodeQlIfRequired(Feature.CliConfigFileEnabled),
|
||||
Feature.QaTelemetryEnabled,
|
||||
includeCodeQlIfRequired(Feature.QaTelemetryEnabled),
|
||||
),
|
||||
"Feature flag should be enabled initially",
|
||||
);
|
||||
|
@ -346,12 +346,12 @@ test("Environment variable can override feature flag cache", async (t) => {
|
|||
fs.existsSync(cachedFeatureFlags),
|
||||
"Feature flag cached file should exist after getting feature flags",
|
||||
);
|
||||
process.env.CODEQL_PASS_CONFIG_TO_CLI = "false";
|
||||
process.env.CODEQL_ACTION_QA_TELEMETRY = "false";
|
||||
|
||||
t.false(
|
||||
await features.getValue(
|
||||
Feature.CliConfigFileEnabled,
|
||||
includeCodeQlIfRequired(Feature.CliConfigFileEnabled),
|
||||
Feature.QaTelemetryEnabled,
|
||||
includeCodeQlIfRequired(Feature.QaTelemetryEnabled),
|
||||
),
|
||||
"Feature flag should be disabled after setting env var",
|
||||
);
|
||||
|
|
|
@ -44,7 +44,6 @@ export interface FeatureEnablement {
|
|||
* Each value of this enum should end with `_enabled`.
|
||||
*/
|
||||
export enum Feature {
|
||||
CliConfigFileEnabled = "cli_config_file_enabled",
|
||||
CodeqlJavaLombokEnabled = "codeql_java_lombok_enabled",
|
||||
CppDependencyInstallation = "cpp_dependency_installation_enabled",
|
||||
DisableKotlinAnalysisEnabled = "disable_kotlin_analysis_enabled",
|
||||
|
@ -73,11 +72,6 @@ export const featureConfig: Record<
|
|||
minimumVersion: undefined,
|
||||
defaultValue: false,
|
||||
},
|
||||
[Feature.CliConfigFileEnabled]: {
|
||||
envVar: "CODEQL_PASS_CONFIG_TO_CLI",
|
||||
minimumVersion: undefined,
|
||||
defaultValue: true,
|
||||
},
|
||||
[Feature.EvaluatorFineGrainedParallelismEnabled]: {
|
||||
envVar: "CODEQL_EVALUATOR_FINE_GRAINED_PARALLELISM",
|
||||
minimumVersion: CODEQL_VERSION_FINE_GRAINED_PARALLELISM,
|
||||
|
@ -447,30 +441,3 @@ class GitHubFeatureFlags {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Whether the Action should generate a code scanning config file
|
||||
* that gets passed to the CLI.
|
||||
*/
|
||||
export async function useCodeScanningConfigInCli(
|
||||
codeql: CodeQL,
|
||||
features: FeatureEnablement,
|
||||
): Promise<boolean> {
|
||||
return await features.getValue(Feature.CliConfigFileEnabled, codeql);
|
||||
}
|
||||
|
||||
export async function logCodeScanningConfigInCli(
|
||||
codeql: CodeQL,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
) {
|
||||
if (await useCodeScanningConfigInCli(codeql, features)) {
|
||||
logger.info(
|
||||
"Code Scanning configuration file being processed in the codeql CLI.",
|
||||
);
|
||||
} else {
|
||||
logger.info(
|
||||
"Code Scanning configuration file being processed in the codeql-action.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -469,7 +469,6 @@ async function run() {
|
|||
sourceRoot,
|
||||
"Runner.Worker.exe",
|
||||
registriesInput,
|
||||
features,
|
||||
apiDetails,
|
||||
logger,
|
||||
);
|
||||
|
|
28
src/init.ts
28
src/init.ts
|
@ -8,11 +8,7 @@ import * as analysisPaths from "./analysis-paths";
|
|||
import { GitHubApiCombinedDetails, GitHubApiDetails } from "./api-client";
|
||||
import { CodeQL, setupCodeQL } from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import {
|
||||
CodeQLDefaultVersionInfo,
|
||||
FeatureEnablement,
|
||||
useCodeScanningConfigInCli,
|
||||
} from "./feature-flags";
|
||||
import { CodeQLDefaultVersionInfo, FeatureEnablement } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
|
@ -103,26 +99,17 @@ export async function runInit(
|
|||
sourceRoot: string,
|
||||
processName: string | undefined,
|
||||
registriesInput: string | undefined,
|
||||
features: FeatureEnablement,
|
||||
apiDetails: GitHubApiCombinedDetails,
|
||||
logger: Logger,
|
||||
): Promise<TracerConfig | undefined> {
|
||||
fs.mkdirSync(config.dbLocation, { recursive: true });
|
||||
try {
|
||||
// When parsing the codeql config in the CLI, we have not yet created the qlconfig file.
|
||||
// So, create it now.
|
||||
// If we are parsing the config file in the Action, then the qlconfig file was already created
|
||||
// before the `pack download` command was invoked. It is not required for the init command.
|
||||
let registriesAuthTokens: string | undefined;
|
||||
let qlconfigFile: string | undefined;
|
||||
if (await useCodeScanningConfigInCli(codeql, features)) {
|
||||
({ registriesAuthTokens, qlconfigFile } =
|
||||
await configUtils.generateRegistries(
|
||||
registriesInput,
|
||||
config.tempDir,
|
||||
logger,
|
||||
));
|
||||
}
|
||||
const { registriesAuthTokens, qlconfigFile } =
|
||||
await configUtils.generateRegistries(
|
||||
registriesInput,
|
||||
config.tempDir,
|
||||
logger,
|
||||
);
|
||||
await configUtils.wrapEnvironment(
|
||||
{
|
||||
GITHUB_TOKEN: apiDetails.auth,
|
||||
|
@ -135,7 +122,6 @@ export async function runInit(
|
|||
config,
|
||||
sourceRoot,
|
||||
processName,
|
||||
features,
|
||||
qlconfigFile,
|
||||
logger,
|
||||
),
|
||||
|
|
Загрузка…
Ссылка в новой задаче