mirror of
https://github.com/github/codeql-action.git
synced 2026-01-03 21:20:09 +08:00
Add ML-powered queries enablement to init status report
We report this information in the `init` status report rather than the `analyze` status report so we can gather data about timeouts.
This commit is contained in:
@@ -15,7 +15,11 @@ import { FeatureFlag, FeatureFlags } from "./feature-flags";
|
||||
import { Language, parseLanguage } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import { codeQlVersionAbove, GitHubVersion } from "./util";
|
||||
import {
|
||||
codeQlVersionAbove,
|
||||
GitHubVersion,
|
||||
ML_POWERED_JS_QUERIES_PACK_NAME,
|
||||
} from "./util";
|
||||
|
||||
// Property names from the user-supplied config file.
|
||||
const NAME_PROPERTY = "name";
|
||||
@@ -298,7 +302,7 @@ async function addBuiltinSuiteQueries(
|
||||
packs.javascript = [];
|
||||
}
|
||||
packs.javascript.push({
|
||||
packName: "codeql/javascript-experimental-atm-queries",
|
||||
packName: ML_POWERED_JS_QUERIES_PACK_NAME,
|
||||
version: "~0.0.2",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
DEFAULT_DEBUG_DATABASE_NAME,
|
||||
checkNotWindows11,
|
||||
getMlPoweredJsQueriesStatus,
|
||||
} from "./util";
|
||||
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
@@ -52,6 +53,12 @@ interface InitSuccessStatusReport extends StatusReportBase {
|
||||
* This may be from the workflow file or may be calculated from repository contents
|
||||
*/
|
||||
languages: string;
|
||||
/**
|
||||
* Information about the enablement of the ML-powered JS query pack.
|
||||
*
|
||||
* @see {@link getMlPoweredJsQueriesStatus}
|
||||
*/
|
||||
ml_powered_js_queries: string;
|
||||
/** Comma-separated list of paths, from the 'paths' config field. */
|
||||
paths: string;
|
||||
/** Comma-separated list of paths, from the 'paths-ignore' config field. */
|
||||
@@ -107,6 +114,7 @@ async function sendSuccessStatusReport(
|
||||
...statusReportBase,
|
||||
disable_default_queries: disableDefaultQueries,
|
||||
languages,
|
||||
ml_powered_js_queries: getMlPoweredJsQueriesStatus(config),
|
||||
paths,
|
||||
paths_ignore: pathsIgnore,
|
||||
queries: queries.join(","),
|
||||
|
||||
@@ -7,6 +7,7 @@ import test, { ExecutionContext } from "ava";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
import * as api from "./api-client";
|
||||
import { Config, PackWithVersion } from "./config-utils";
|
||||
import { getRunnerLogger, Logger } from "./logging";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import * as util from "./util";
|
||||
@@ -291,3 +292,51 @@ async function mockStdInForAuthExpectError(
|
||||
util.getGitHubAuth(mockLogger, undefined, true, stdin)
|
||||
);
|
||||
}
|
||||
|
||||
const ML_POWERED_JS_STATUS_TESTS: Array<[PackWithVersion[], string]> = [
|
||||
[[], "false"],
|
||||
[[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME }], "latest"],
|
||||
[
|
||||
[{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME, version: "0.0.2" }],
|
||||
"0.0.2",
|
||||
],
|
||||
[
|
||||
[
|
||||
{ packName: "someOtherPack" },
|
||||
{ packName: util.ML_POWERED_JS_QUERIES_PACK_NAME },
|
||||
],
|
||||
"latest",
|
||||
],
|
||||
];
|
||||
|
||||
for (const [packs, expectedStatus] of ML_POWERED_JS_STATUS_TESTS) {
|
||||
const packDescriptions = `[${packs
|
||||
.map((pack) => JSON.stringify(pack))
|
||||
.join(", ")}]`;
|
||||
test(`ML-powered JS queries status report is "${expectedStatus}" for packs = ${packDescriptions}`, (t) => {
|
||||
return util.withTmpDir(async (tmpDir) => {
|
||||
const config: Config = {
|
||||
languages: [],
|
||||
queries: {},
|
||||
paths: [],
|
||||
pathsIgnore: [],
|
||||
originalUserInput: {},
|
||||
tempDir: tmpDir,
|
||||
toolCacheDir: tmpDir,
|
||||
codeQLCmd: "",
|
||||
gitHubVersion: {
|
||||
type: util.GitHubVariant.DOTCOM,
|
||||
} as util.GitHubVersion,
|
||||
dbLocation: "",
|
||||
packs: {
|
||||
javascript: packs,
|
||||
},
|
||||
debugMode: false,
|
||||
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
||||
};
|
||||
|
||||
t.is(util.getMlPoweredJsQueriesStatus(config), expectedStatus);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
25
src/util.ts
25
src/util.ts
@@ -627,3 +627,28 @@ export function checkNotWindows11() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const ML_POWERED_JS_QUERIES_PACK_NAME =
|
||||
"codeql/javascript-experimental-atm-queries";
|
||||
|
||||
/** Get information about ML-powered JS queries to populate status reports with.
|
||||
*
|
||||
* This will be:
|
||||
*
|
||||
* - The version string if the analysis will use a specific version of the pack
|
||||
* - "latest" if the analysis will use the latest version of the pack
|
||||
* - "false" if the analysis won't run any ML-powered JS queries, or if the analysis will run
|
||||
* multiple ML-powered JS query packs
|
||||
*
|
||||
* This function lives here rather than in `init-action.ts` so it's easier to test, since tests for
|
||||
* `init-action.ts` would each need to live in their own file. See `analyze-action-env.ts` for an
|
||||
* explanation as to why this is.
|
||||
*/
|
||||
export function getMlPoweredJsQueriesStatus(config: Config) {
|
||||
const mlPoweredJsQueryPacks = (config.packs.javascript || []).filter(
|
||||
(pack) => pack.packName === ML_POWERED_JS_QUERIES_PACK_NAME
|
||||
);
|
||||
return mlPoweredJsQueryPacks.length === 1
|
||||
? mlPoweredJsQueryPacks[0].version || "latest"
|
||||
: "false";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user