Resolve the final dependency cycle!
This commit is contained in:
parent
5658fd1df2
commit
bac7c32ff7
13 changed files with 106 additions and 105 deletions
|
|
@ -7,11 +7,7 @@ import * as yaml from "js-yaml";
|
|||
|
||||
import { getOptionalInput, isAnalyzingDefaultBranch } from "./actions-util";
|
||||
import * as api from "./api-client";
|
||||
import {
|
||||
Config,
|
||||
getGeneratedCodeScanningConfigPath,
|
||||
getMlPoweredJsQueriesPack,
|
||||
} from "./config-utils";
|
||||
import type { Config } from "./config-utils";
|
||||
import { EnvVar } from "./environment";
|
||||
import { errorMatchers } from "./error-matcher";
|
||||
import {
|
||||
|
|
@ -1211,7 +1207,7 @@ async function generateCodeScanningConfig(
|
|||
if (config.augmentationProperties.injectedMlQueries) {
|
||||
// We need to inject the ML queries into the original user input before
|
||||
// we pass this on to the CLI, to make sure these get run.
|
||||
const packString = await getMlPoweredJsQueriesPack(codeql);
|
||||
const packString = await util.getMlPoweredJsQueriesPack(codeql);
|
||||
|
||||
if (augmentedConfig.packs === undefined) augmentedConfig.packs = [];
|
||||
if (Array.isArray(augmentedConfig.packs)) {
|
||||
|
|
@ -1287,3 +1283,12 @@ export async function getTrapCachingExtractorConfigArgsForLang(
|
|||
`-O=${language}.trap.cache.write=${write}`,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the code scanning configuration generated by the CLI.
|
||||
*
|
||||
* This will not exist if the configuration is being parsed in the Action.
|
||||
*/
|
||||
export function getGeneratedCodeScanningConfigPath(config: Config): string {
|
||||
return path.resolve(config.tempDir, "user-config.yaml");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import {
|
|||
setCodeQL,
|
||||
} from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { ML_POWERED_JS_QUERIES_PACK_NAME } from "./config-utils";
|
||||
import { Feature } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger, Logger } from "./logging";
|
||||
|
|
@ -27,8 +26,10 @@ import {
|
|||
import {
|
||||
DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
DEFAULT_DEBUG_DATABASE_NAME,
|
||||
ML_POWERED_JS_QUERIES_PACK_NAME,
|
||||
GitHubVariant,
|
||||
GitHubVersion,
|
||||
prettyPrintPack,
|
||||
UserError,
|
||||
withTmpDir,
|
||||
} from "./util";
|
||||
|
|
@ -1914,7 +1915,7 @@ const packSpecPrettyPrintingMacro = test.macro({
|
|||
exec: (t: ExecutionContext, packStr: string, packObj: configUtils.Pack) => {
|
||||
const parsed = configUtils.parsePacksSpecification(packStr);
|
||||
t.deepEqual(parsed, packObj, "parsed pack spec is correct");
|
||||
const stringified = configUtils.prettyPrintPack(packObj);
|
||||
const stringified = prettyPrintPack(packObj);
|
||||
t.deepEqual(
|
||||
stringified,
|
||||
packStr.trim(),
|
||||
|
|
|
|||
|
|
@ -28,7 +28,14 @@ import {
|
|||
import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import { downloadTrapCaches } from "./trap-caching";
|
||||
import { codeQlVersionAbove, GitHubVersion, UserError } from "./util";
|
||||
import {
|
||||
codeQlVersionAbove,
|
||||
getMlPoweredJsQueriesPack,
|
||||
GitHubVersion,
|
||||
ML_POWERED_JS_QUERIES_PACK_NAME,
|
||||
prettyPrintPack,
|
||||
UserError,
|
||||
} from "./util";
|
||||
|
||||
// Property names from the user-supplied config file.
|
||||
const NAME_PROPERTY = "name";
|
||||
|
|
@ -1592,12 +1599,6 @@ export function parsePacksSpecification(
|
|||
};
|
||||
}
|
||||
|
||||
export function prettyPrintPack(pack: Pack) {
|
||||
return `${pack.name}${pack.version ? `@${pack.version}` : ""}${
|
||||
pack.path ? `:${pack.path}` : ""
|
||||
}`;
|
||||
}
|
||||
|
||||
export function validatePackSpecification(pack: string, configFile?: string) {
|
||||
return prettyPrintPack(parsePacksSpecification(pack, configFile));
|
||||
}
|
||||
|
|
@ -1663,28 +1664,6 @@ function combinePacks(packs1: Packs, packs2: Packs): Packs {
|
|||
return packs;
|
||||
}
|
||||
|
||||
export const ML_POWERED_JS_QUERIES_PACK_NAME =
|
||||
"codeql/javascript-experimental-atm-queries";
|
||||
|
||||
/**
|
||||
* Gets the ML-powered JS query pack to add to the analysis if a repo is opted into the ML-powered
|
||||
* queries beta.
|
||||
*/
|
||||
export async function getMlPoweredJsQueriesPack(
|
||||
codeQL: CodeQL
|
||||
): Promise<string> {
|
||||
let version;
|
||||
if (await codeQlVersionAbove(codeQL, "2.11.3")) {
|
||||
version = "~0.4.0";
|
||||
} else {
|
||||
version = `~0.3.0`;
|
||||
}
|
||||
return prettyPrintPack({
|
||||
name: ML_POWERED_JS_QUERIES_PACK_NAME,
|
||||
version,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about ML-powered JS queries to populate status reports with.
|
||||
*
|
||||
|
|
@ -1710,8 +1689,7 @@ export function getMlPoweredJsQueriesStatus(config: Config): string {
|
|||
const mlPoweredJsQueryPacks = (config.packs.javascript || [])
|
||||
.map((p) => parsePacksSpecification(p))
|
||||
.filter(
|
||||
(pack) =>
|
||||
pack.name === "codeql/javascript-experimental-atm-queries" && !pack.path
|
||||
(pack) => pack.name === ML_POWERED_JS_QUERIES_PACK_NAME && !pack.path
|
||||
);
|
||||
switch (mlPoweredJsQueryPacks.length) {
|
||||
case 1:
|
||||
|
|
@ -2137,12 +2115,3 @@ export async function wrapEnvironment(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the code scanning configuration generated by the CLI.
|
||||
*
|
||||
* This will not exist if the configuration is being parsed in the Action.
|
||||
*/
|
||||
export function getGeneratedCodeScanningConfigPath(config: Config): string {
|
||||
return path.resolve(config.tempDir, "user-config.yaml");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import * as cache from "@actions/cache";
|
|||
|
||||
import * as actionsUtil from "./actions-util";
|
||||
import { CodeQL, CODEQL_VERSION_BETTER_RESOLVE_LANGUAGES } from "./codeql";
|
||||
import { Config } from "./config-utils";
|
||||
import type { Config } from "./config-utils";
|
||||
import { Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { codeQlVersionAbove, tryGetFolderBytes, withTimeout } from "./util";
|
||||
|
|
|
|||
30
src/util.ts
30
src/util.ts
|
|
@ -10,7 +10,7 @@ import * as semver from "semver";
|
|||
|
||||
import * as apiCompatibility from "./api-compatibility.json";
|
||||
import type { CodeQL } from "./codeql";
|
||||
import type { Config } from "./config-utils";
|
||||
import type { Config, Pack } from "./config-utils";
|
||||
import { EnvVar } from "./environment";
|
||||
import { Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
|
|
@ -794,3 +794,31 @@ export function fixInvalidNotificationsInFile(
|
|||
export function wrapError(error: unknown): Error {
|
||||
return error instanceof Error ? error : new Error(String(error));
|
||||
}
|
||||
|
||||
export const ML_POWERED_JS_QUERIES_PACK_NAME =
|
||||
"codeql/javascript-experimental-atm-queries";
|
||||
|
||||
/**
|
||||
* Gets the ML-powered JS query pack to add to the analysis if a repo is opted into the ML-powered
|
||||
* queries beta.
|
||||
*/
|
||||
export async function getMlPoweredJsQueriesPack(
|
||||
codeQL: CodeQL
|
||||
): Promise<string> {
|
||||
let version;
|
||||
if (await codeQlVersionAbove(codeQL, "2.11.3")) {
|
||||
version = "~0.4.0";
|
||||
} else {
|
||||
version = `~0.3.0`;
|
||||
}
|
||||
return prettyPrintPack({
|
||||
name: ML_POWERED_JS_QUERIES_PACK_NAME,
|
||||
version,
|
||||
});
|
||||
}
|
||||
|
||||
export function prettyPrintPack(pack: Pack) {
|
||||
return `${pack.name}${pack.version ? `@${pack.version}` : ""}${
|
||||
pack.path ? `:${pack.path}` : ""
|
||||
}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue