Packaging: Address review comments
1. Better malformed data guard for PackDownloadOutput 2. Fix Packs type 3. Remove TODO in init-action
This commit is contained in:
parent
d87945e9fd
commit
1cc5f1d5dd
14 changed files with 39 additions and 69 deletions
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"analysis-paths.test.js","sourceRoot":"","sources":["../src/analysis-paths.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA6B;AAE7B,8CAAuB;AAEvB,gEAAkD;AAElD,mDAA6C;AAC7C,6CAA+B;AAE/B,0BAAU,CAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,YAAY,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC7B,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG;YACb,SAAS,EAAE,EAAE;YACb,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,EAAE;YACf,KAAK,EAAE,EAAE;YACT,iBAAiB,EAAE,EAAE;YACrB,OAAO,EAAE,MAAM;YACf,YAAY,EAAE,MAAM;YACpB,SAAS,EAAE,EAAE;YACb,aAAa,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,EAAwB;YACxE,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,kBAAkB,CAAC;YACpD,KAAK,EAAE,EAAW;SACnB,CAAC;QACF,aAAa,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;A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,GAAG,CAAC,oBAAoB,CAAC,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
1
lib/analyze.test.js
generated
1
lib/analyze.test.js
generated
|
|
@ -57,6 +57,7 @@ ava_1.default("status report fields and search path setting", async (t) => {
|
|||
};
|
||||
for (const language of Object.values(languages_1.Language)) {
|
||||
codeql_1.setCodeQL({
|
||||
packDownload: async () => ({ packs: [] }),
|
||||
databaseAnalyze: async (_, sarifFile, searchPath) => {
|
||||
fs.writeFileSync(sarifFile, JSON.stringify({
|
||||
runs: [
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
11
lib/codeql.js
generated
11
lib/codeql.js
generated
|
|
@ -526,10 +526,17 @@ function getCodeQLForCmd(cmd) {
|
|||
},
|
||||
}).exec();
|
||||
try {
|
||||
return JSON.parse(output);
|
||||
const parsedOutput = JSON.parse(output);
|
||||
if (Array.isArray(parsedOutput.packs) &&
|
||||
parsedOutput.packs.every((p) => p.name && p.version)) {
|
||||
return parsedOutput;
|
||||
}
|
||||
else {
|
||||
throw new Error("Unexpected output from pack download");
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(`Attempted to download specified packs but got an error:${"\n"}${output}.`);
|
||||
throw new Error(`Attempted to download specified packs but got an error:\n${output}\n${e}`);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
2
lib/config-utils.js
generated
2
lib/config-utils.js
generated
|
|
@ -627,7 +627,7 @@ async function initConfig(languagesInput, queriesInput, configFile, dbLocation,
|
|||
for (const language of config.languages) {
|
||||
const hasBuiltinQueries = ((_a = config.queries[language]) === null || _a === void 0 ? void 0 : _a.builtin.length) > 0;
|
||||
const hasCustomQueries = ((_b = config.queries[language]) === null || _b === void 0 ? void 0 : _b.custom.length) > 0;
|
||||
const hasPacks = ((_c = config.packs[language]) === null || _c === void 0 ? void 0 : _c.length) > 0;
|
||||
const hasPacks = (((_c = config.packs[language]) === null || _c === void 0 ? void 0 : _c.length) || 0) > 0;
|
||||
if (!hasPacks && !hasBuiltinQueries && !hasCustomQueries) {
|
||||
throw new Error(`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.");
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
20
lib/init-action.js
generated
20
lib/init-action.js
generated
|
|
@ -7,11 +7,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const yaml = __importStar(require("js-yaml"));
|
||||
const actions_util_1 = require("./actions-util");
|
||||
const init_1 = require("./init");
|
||||
const languages_1 = require("./languages");
|
||||
|
|
@ -86,22 +82,6 @@ async function run() {
|
|||
logger.warning(`${err.message} You can call this action with 'setup-python-dependencies: false' to disable this process`);
|
||||
}
|
||||
}
|
||||
////////////////////////////////
|
||||
// TODO This should not happen in the action, we should be able to
|
||||
// generate the default qlconfig from the CLI
|
||||
// DO NOT COMMIT THIS
|
||||
const defaultQlConfig = {
|
||||
registryKind: "docker",
|
||||
registries: [
|
||||
{
|
||||
url: "https://ghcr.io/v2/",
|
||||
packages: "*",
|
||||
},
|
||||
],
|
||||
};
|
||||
fs.mkdirSync(path.join(os.homedir(), ".codeql"));
|
||||
fs.writeFileSync(path.join(os.homedir(), ".codeql", "qlconfig.yml"), yaml.safeDump(defaultQlConfig), "utf8");
|
||||
////////////////////////////////
|
||||
}
|
||||
catch (e) {
|
||||
core.setFailed(e.message);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -3,7 +3,6 @@ import * as path from "path";
|
|||
import test from "ava";
|
||||
|
||||
import * as analysisPaths from "./analysis-paths";
|
||||
import { Packs } from "./config-utils";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import * as util from "./util";
|
||||
|
||||
|
|
@ -22,7 +21,7 @@ test("emptyPaths", async (t) => {
|
|||
codeQLCmd: "",
|
||||
gitHubVersion: { type: util.GitHubVariant.DOTCOM } as util.GitHubVersion,
|
||||
dbLocation: path.resolve(tmpDir, "codeql_databases"),
|
||||
packs: {} as Packs,
|
||||
packs: {},
|
||||
};
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
|
||||
|
|
@ -44,7 +43,7 @@ test("nonEmptyPaths", async (t) => {
|
|||
codeQLCmd: "",
|
||||
gitHubVersion: { type: util.GitHubVariant.DOTCOM } as util.GitHubVersion,
|
||||
dbLocation: path.resolve(tmpDir, "codeql_databases"),
|
||||
packs: {} as Packs,
|
||||
packs: {},
|
||||
};
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
t.is(process.env["LGTM_INDEX_INCLUDE"], "path1\npath2");
|
||||
|
|
@ -70,7 +69,7 @@ test("exclude temp dir", async (t) => {
|
|||
codeQLCmd: "",
|
||||
gitHubVersion: { type: util.GitHubVariant.DOTCOM } as util.GitHubVersion,
|
||||
dbLocation: path.resolve(tempDir, "codeql_databases"),
|
||||
packs: {} as Packs,
|
||||
packs: {},
|
||||
};
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import sinon from "sinon";
|
|||
|
||||
import { runQueries } from "./analyze";
|
||||
import { setCodeQL } from "./codeql";
|
||||
import { Config, Packs } from "./config-utils";
|
||||
import { Config } from "./config-utils";
|
||||
import { getIdPrefix } from "./count-loc";
|
||||
import * as count from "./count-loc";
|
||||
import { Language } from "./languages";
|
||||
|
|
@ -39,19 +39,20 @@ test("status report fields and search path setting", async (t) => {
|
|||
[Language.cpp]: [
|
||||
{
|
||||
packName: "a/b",
|
||||
version: clean("1.0.0"),
|
||||
version: clean("1.0.0")!,
|
||||
},
|
||||
],
|
||||
[Language.java]: [
|
||||
{
|
||||
packName: "c/d",
|
||||
version: clean("2.0.0"),
|
||||
version: clean("2.0.0")!,
|
||||
},
|
||||
],
|
||||
} as Packs;
|
||||
};
|
||||
|
||||
for (const language of Object.values(Language)) {
|
||||
setCodeQL({
|
||||
packDownload: async () => ({ packs: [] }),
|
||||
databaseAnalyze: async (
|
||||
_,
|
||||
sarifFile: string,
|
||||
|
|
|
|||
|
|
@ -796,10 +796,18 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
}).exec();
|
||||
|
||||
try {
|
||||
return JSON.parse(output) as PackDownloadOutput;
|
||||
const parsedOutput: PackDownloadOutput = JSON.parse(output);
|
||||
if (
|
||||
Array.isArray(parsedOutput.packs) &&
|
||||
parsedOutput.packs.every((p) => p.name && p.version)
|
||||
) {
|
||||
return parsedOutput;
|
||||
} else {
|
||||
throw new Error("Unexpected output from pack download");
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
`Attempted to download specified packs but got an error:${"\n"}${output}.`
|
||||
`Attempted to download specified packs but got an error:\n${output}\n${e}`
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ export interface Config {
|
|||
packs: Packs;
|
||||
}
|
||||
|
||||
export type Packs = Record<Partial<Language>, PackWithVersion[]>;
|
||||
export type Packs = Partial<Record<Language, PackWithVersion[]>>;
|
||||
|
||||
export interface PackWithVersion {
|
||||
/** qualified name of a package reference */
|
||||
|
|
@ -1032,8 +1032,8 @@ export function parsePacks(
|
|||
packsByLanguage: string[] | Record<string, string[]> | undefined,
|
||||
languages: Language[],
|
||||
configFile: string
|
||||
) {
|
||||
const packs = {} as Packs;
|
||||
): Packs {
|
||||
const packs = {};
|
||||
|
||||
if (!packsByLanguage) {
|
||||
return packs;
|
||||
|
|
@ -1071,6 +1071,7 @@ function toPackWithVersion(packStr, configFile: string): PackWithVersion {
|
|||
if (typeof packStr !== "string") {
|
||||
throw new Error(getPacksStrInvalid(packStr, configFile));
|
||||
}
|
||||
|
||||
const nameWithVersion = packStr.split("@");
|
||||
let version: string | undefined;
|
||||
if (
|
||||
|
|
@ -1158,7 +1159,7 @@ export async function initConfig(
|
|||
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;
|
||||
const hasPacks = (config.packs[language]?.length || 0) > 0;
|
||||
if (!hasPacks && !hasBuiltinQueries && !hasCustomQueries) {
|
||||
throw new Error(
|
||||
`Did not detect any queries to run for ${language}. ` +
|
||||
|
|
|
|||
|
|
@ -1,9 +1,4 @@
|
|||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import * as yaml from "js-yaml";
|
||||
|
||||
import {
|
||||
createStatusReportBase,
|
||||
|
|
@ -182,28 +177,6 @@ async function run() {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// TODO This should not happen in the action, we should be able to
|
||||
// generate the default qlconfig from the CLI
|
||||
// DO NOT COMMIT THIS
|
||||
const defaultQlConfig = {
|
||||
registryKind: "docker",
|
||||
registries: [
|
||||
{
|
||||
url: "https://ghcr.io/v2/",
|
||||
packages: "*",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
fs.mkdirSync(path.join(os.homedir(), ".codeql"));
|
||||
fs.writeFileSync(
|
||||
path.join(os.homedir(), ".codeql", "qlconfig.yml"),
|
||||
yaml.safeDump(defaultQlConfig),
|
||||
"utf8"
|
||||
);
|
||||
////////////////////////////////
|
||||
} catch (e) {
|
||||
core.setFailed(e.message);
|
||||
console.log(e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue