mirror of
https://github.com/github/codeql-action.git
synced 2026-01-05 06:00:32 +08:00
Make name of debugging artifact and DB within it configurable
This commit is contained in:
@@ -23,6 +23,8 @@ test("emptyPaths", async (t) => {
|
||||
dbLocation: path.resolve(tmpDir, "codeql_databases"),
|
||||
packs: {},
|
||||
debugMode: false,
|
||||
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
||||
};
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
|
||||
@@ -46,6 +48,8 @@ test("nonEmptyPaths", async (t) => {
|
||||
dbLocation: path.resolve(tmpDir, "codeql_databases"),
|
||||
packs: {},
|
||||
debugMode: false,
|
||||
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
||||
};
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
t.is(process.env["LGTM_INDEX_INCLUDE"], "path1\npath2");
|
||||
@@ -73,6 +77,8 @@ test("exclude temp dir", async (t) => {
|
||||
dbLocation: path.resolve(tempDir, "codeql_databases"),
|
||||
packs: {},
|
||||
debugMode: false,
|
||||
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
||||
};
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
|
||||
|
||||
@@ -21,7 +21,7 @@ import { parseRepositoryNwo } from "./repository";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
import { UploadResult } from "./upload-lib";
|
||||
import * as util from "./util";
|
||||
import { bundleDb, codeQlVersionAbove, DEBUG_ARTIFACT_NAME } from "./util";
|
||||
import { bundleDb, codeQlVersionAbove } from "./util";
|
||||
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
const pkg = require("../package.json");
|
||||
@@ -135,7 +135,8 @@ async function run() {
|
||||
config.languages.map((lang) =>
|
||||
path.resolve(outputDir, `${lang}.sarif`)
|
||||
),
|
||||
outputDir
|
||||
outputDir,
|
||||
config.debugArtifactName
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -156,12 +157,17 @@ async function run() {
|
||||
// Multilanguage tracing: there are additional logs in the root of the cluster
|
||||
toUpload.push(...listFolder(path.resolve(config.dbLocation, "log")));
|
||||
}
|
||||
await uploadDebugArtifacts(toUpload, config.dbLocation);
|
||||
await uploadDebugArtifacts(
|
||||
toUpload,
|
||||
config.dbLocation,
|
||||
config.debugArtifactName
|
||||
);
|
||||
if (!(await codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING))) {
|
||||
// Before multi-language tracing, we wrote a compound-build-tracer.log in the temp dir
|
||||
await uploadDebugArtifacts(
|
||||
[path.resolve(config.tempDir, "compound-build-tracer.log")],
|
||||
config.tempDir
|
||||
config.tempDir,
|
||||
config.debugArtifactName
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -232,10 +238,19 @@ async function run() {
|
||||
const toUpload: string[] = [];
|
||||
for (const language of config.languages) {
|
||||
toUpload.push(
|
||||
await bundleDb(config, language, await getCodeQL(config.codeQLCmd))
|
||||
await bundleDb(
|
||||
config,
|
||||
language,
|
||||
await getCodeQL(config.codeQLCmd),
|
||||
`${config.debugDatabaseName}-${language}`
|
||||
)
|
||||
);
|
||||
}
|
||||
await uploadDebugArtifacts(toUpload, config.dbLocation);
|
||||
await uploadDebugArtifacts(
|
||||
toUpload,
|
||||
config.dbLocation,
|
||||
config.debugArtifactName
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(`Failed to upload database debug bundles: ${error}`);
|
||||
}
|
||||
@@ -280,7 +295,11 @@ async function run() {
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadDebugArtifacts(toUpload: string[], rootDir: string) {
|
||||
async function uploadDebugArtifacts(
|
||||
toUpload: string[],
|
||||
rootDir: string,
|
||||
artifactName: string
|
||||
) {
|
||||
let suffix = "";
|
||||
const matrix = actionsUtil.getRequiredInput("matrix");
|
||||
if (matrix !== undefined && matrix !== "null") {
|
||||
@@ -288,7 +307,7 @@ async function uploadDebugArtifacts(toUpload: string[], rootDir: string) {
|
||||
suffix += `-${entry[1]}`;
|
||||
}
|
||||
await artifact.create().uploadArtifact(
|
||||
actionsUtil.sanitizeArifactName(`${DEBUG_ARTIFACT_NAME}${suffix}`),
|
||||
actionsUtil.sanitizeArifactName(`${artifactName}${suffix}`),
|
||||
toUpload.map((file) => path.normalize(file)),
|
||||
path.normalize(rootDir)
|
||||
);
|
||||
|
||||
@@ -120,6 +120,8 @@ test("status report fields and search path setting", async (t) => {
|
||||
dbLocation: path.resolve(tmpDir, "codeql_databases"),
|
||||
packs,
|
||||
debugMode: false,
|
||||
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
||||
};
|
||||
fs.mkdirSync(util.getCodeQLDatabasePath(config, language), {
|
||||
recursive: true,
|
||||
|
||||
@@ -127,7 +127,11 @@ export interface CodeQL {
|
||||
/**
|
||||
* Run 'codeql database bundle'.
|
||||
*/
|
||||
databaseBundle(databasePath: string, outputFilePath: string): Promise<void>;
|
||||
databaseBundle(
|
||||
databasePath: string,
|
||||
outputFilePath: string,
|
||||
dbName: string
|
||||
): Promise<void>;
|
||||
/**
|
||||
* Run 'codeql database run-queries'.
|
||||
*/
|
||||
@@ -957,13 +961,15 @@ async function getCodeQLForCmd(
|
||||
},
|
||||
async databaseBundle(
|
||||
databasePath: string,
|
||||
outputFilePath: string
|
||||
outputFilePath: string,
|
||||
databaseName: string
|
||||
): Promise<void> {
|
||||
const args = [
|
||||
"database",
|
||||
"bundle",
|
||||
databasePath,
|
||||
`--output=${outputFilePath}`,
|
||||
`--name=${databaseName}`,
|
||||
];
|
||||
await new toolrunner.ToolRunner(cmd, args).exec();
|
||||
},
|
||||
|
||||
@@ -87,6 +87,8 @@ test("load empty config", async (t) => {
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -106,6 +108,8 @@ test("load empty config", async (t) => {
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -150,6 +154,8 @@ test("loading config saves config", async (t) => {
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -180,6 +186,8 @@ test("load input outside of workspace", async (t) => {
|
||||
"../input",
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -217,6 +225,8 @@ test("load non-local input with invalid repo syntax", async (t) => {
|
||||
configFile,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -255,6 +265,8 @@ test("load non-existent input", async (t) => {
|
||||
configFile,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -340,6 +352,8 @@ test("load non-empty input", async (t) => {
|
||||
dbLocation: path.resolve(tmpDir, "codeql_databases"),
|
||||
packs: {} as configUtils.Packs,
|
||||
debugMode: false,
|
||||
debugArtifactName: "my-artifact",
|
||||
debugDatabaseName: "my-db",
|
||||
};
|
||||
|
||||
const languages = "javascript";
|
||||
@@ -352,6 +366,8 @@ test("load non-empty input", async (t) => {
|
||||
configFilePath,
|
||||
undefined,
|
||||
false,
|
||||
"my-artifact",
|
||||
"my-db",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -417,6 +433,8 @@ test("Default queries are used", async (t) => {
|
||||
configFilePath,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -490,6 +508,8 @@ test("Queries can be specified in config file", async (t) => {
|
||||
configFilePath,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -557,6 +577,8 @@ test("Queries from config file can be overridden in workflow file", async (t) =>
|
||||
configFilePath,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -622,6 +644,8 @@ test("Queries in workflow file can be used in tandem with the 'disable default q
|
||||
configFilePath,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -680,6 +704,8 @@ test("Multiple queries can be specified in workflow file, no config file require
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -759,6 +785,8 @@ test("Queries in workflow file can be added to the set of queries without overri
|
||||
configFilePath,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -828,6 +856,8 @@ test("Invalid queries in workflow file handled correctly", async (t) => {
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -894,6 +924,8 @@ test("API client used when reading remote config", async (t) => {
|
||||
configFile,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -922,6 +954,8 @@ test("Remote config handles the case where a directory is provided", async (t) =
|
||||
repoReference,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -958,6 +992,8 @@ test("Invalid format of remote config handled correctly", async (t) => {
|
||||
repoReference,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -995,6 +1031,8 @@ test("No detected languages", async (t) => {
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -1024,6 +1062,8 @@ test("Unknown languages", async (t) => {
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -1075,6 +1115,8 @@ test("Config specifies packages", async (t) => {
|
||||
configFile,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -1135,6 +1177,8 @@ test("Config specifies packages for multiple languages", async (t) => {
|
||||
configFile,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example" },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -1211,6 +1255,8 @@ function doInvalidInputTest(
|
||||
configFile,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
@@ -1684,6 +1730,8 @@ async function mlPoweredQueriesMacro(
|
||||
undefined,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
{ owner: "github", repo: "example " },
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
|
||||
@@ -135,6 +135,14 @@ export interface Config {
|
||||
* output for debugging purposes when possible.
|
||||
*/
|
||||
debugMode: boolean;
|
||||
/**
|
||||
* Specifies the name of the debugging artifact if we are in debug mode.
|
||||
*/
|
||||
debugArtifactName: string;
|
||||
/**
|
||||
* Specifies the name of the database in the debugging artifact.
|
||||
*/
|
||||
debugDatabaseName: string;
|
||||
}
|
||||
|
||||
export type Packs = Partial<Record<Language, PackWithVersion[]>>;
|
||||
@@ -852,6 +860,8 @@ export async function getDefaultConfig(
|
||||
packsInput: string | undefined,
|
||||
dbLocation: string | undefined,
|
||||
debugMode: boolean,
|
||||
debugArtifactName: string,
|
||||
debugDatabaseName: string,
|
||||
repository: RepositoryNwo,
|
||||
tempDir: string,
|
||||
toolCacheDir: string,
|
||||
@@ -906,6 +916,8 @@ export async function getDefaultConfig(
|
||||
gitHubVersion,
|
||||
dbLocation: dbLocationOrDefault(dbLocation, tempDir),
|
||||
debugMode,
|
||||
debugArtifactName,
|
||||
debugDatabaseName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -919,6 +931,8 @@ async function loadConfig(
|
||||
configFile: string,
|
||||
dbLocation: string | undefined,
|
||||
debugMode: boolean,
|
||||
debugArtifactName: string,
|
||||
debugDatabaseName: string,
|
||||
repository: RepositoryNwo,
|
||||
tempDir: string,
|
||||
toolCacheDir: string,
|
||||
@@ -1081,6 +1095,8 @@ async function loadConfig(
|
||||
gitHubVersion,
|
||||
dbLocation: dbLocationOrDefault(dbLocation, tempDir),
|
||||
debugMode,
|
||||
debugArtifactName,
|
||||
debugDatabaseName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1251,6 +1267,8 @@ export async function initConfig(
|
||||
configFile: string | undefined,
|
||||
dbLocation: string | undefined,
|
||||
debugMode: boolean,
|
||||
debugArtifactName: string,
|
||||
debugDatabaseName: string,
|
||||
repository: RepositoryNwo,
|
||||
tempDir: string,
|
||||
toolCacheDir: string,
|
||||
@@ -1272,6 +1290,8 @@ export async function initConfig(
|
||||
packsInput,
|
||||
dbLocation,
|
||||
debugMode,
|
||||
debugArtifactName,
|
||||
debugDatabaseName,
|
||||
repository,
|
||||
tempDir,
|
||||
toolCacheDir,
|
||||
@@ -1290,6 +1310,8 @@ export async function initConfig(
|
||||
configFile,
|
||||
dbLocation,
|
||||
debugMode,
|
||||
debugArtifactName,
|
||||
debugDatabaseName,
|
||||
repository,
|
||||
tempDir,
|
||||
toolCacheDir,
|
||||
|
||||
@@ -20,6 +20,8 @@ import {
|
||||
setupTests,
|
||||
} from "./testing-utils";
|
||||
import {
|
||||
DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
DEFAULT_DEBUG_DATABASE_NAME,
|
||||
GitHubVariant,
|
||||
HTTPError,
|
||||
initializeEnvironment,
|
||||
@@ -58,6 +60,8 @@ function getTestConfig(tmpDir: string): Config {
|
||||
dbLocation: tmpDir,
|
||||
packs: {},
|
||||
debugMode: false,
|
||||
debugArtifactName: DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
debugDatabaseName: DEFAULT_DEBUG_DATABASE_NAME,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,9 @@ export async function uploadDatabases(
|
||||
// Although we are uploading arbitrary file contents to the API, it's worth
|
||||
// noting that it's the API's job to validate that the contents is acceptable.
|
||||
// This API method is available to anyone with write access to the repo.
|
||||
const payload = fs.readFileSync(await bundleDb(config, language, codeql));
|
||||
const payload = fs.readFileSync(
|
||||
await bundleDb(config, language, codeql, language)
|
||||
);
|
||||
try {
|
||||
if (useUploadDomain) {
|
||||
await client.request(
|
||||
|
||||
@@ -35,6 +35,8 @@ import {
|
||||
enrichEnvironment,
|
||||
getMemoryFlagValue,
|
||||
getThreadsFlagValue,
|
||||
DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
DEFAULT_DEBUG_DATABASE_NAME,
|
||||
} from "./util";
|
||||
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
@@ -177,6 +179,8 @@ async function run() {
|
||||
getOptionalInput("config-file"),
|
||||
getOptionalInput("db-location"),
|
||||
getOptionalInput("debug") === "true",
|
||||
getOptionalInput("debug-artifact-name") || DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
getOptionalInput("debug-database-name") || DEFAULT_DEBUG_DATABASE_NAME,
|
||||
repositoryNwo,
|
||||
getTemporaryDirectory(),
|
||||
getRequiredEnvParam("RUNNER_TOOL_CACHE"),
|
||||
|
||||
@@ -45,6 +45,8 @@ export async function initConfig(
|
||||
configFile: string | undefined,
|
||||
dbLocation: string | undefined,
|
||||
debugMode: boolean,
|
||||
debugArtifactName: string,
|
||||
debugDatabaseName: string,
|
||||
repository: RepositoryNwo,
|
||||
tempDir: string,
|
||||
toolCacheDir: string,
|
||||
@@ -63,6 +65,8 @@ export async function initConfig(
|
||||
configFile,
|
||||
dbLocation,
|
||||
debugMode,
|
||||
debugArtifactName,
|
||||
debugDatabaseName,
|
||||
repository,
|
||||
tempDir,
|
||||
toolCacheDir,
|
||||
|
||||
@@ -252,6 +252,8 @@ program
|
||||
cmd.configFile,
|
||||
undefined,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
parseRepositoryNwo(cmd.repository),
|
||||
tempDir,
|
||||
toolsDir,
|
||||
|
||||
@@ -30,6 +30,8 @@ function getTestConfig(tmpDir: string): configUtils.Config {
|
||||
dbLocation: path.resolve(tmpDir, "codeql_databases"),
|
||||
packs: {},
|
||||
debugMode: false,
|
||||
debugArtifactName: util.DEFAULT_DEBUG_ARTIFACT_NAME,
|
||||
debugDatabaseName: util.DEFAULT_DEBUG_DATABASE_NAME,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
19
src/util.ts
19
src/util.ts
@@ -26,9 +26,14 @@ const BROKEN_VERSIONS = ["0.0.0-20211207"];
|
||||
export const GITHUB_DOTCOM_URL = "https://github.com";
|
||||
|
||||
/**
|
||||
* Name of the debugging artifact.
|
||||
* Default name of the debugging artifact.
|
||||
*/
|
||||
export const DEBUG_ARTIFACT_NAME = "debug-artifacts";
|
||||
export const DEFAULT_DEBUG_ARTIFACT_NAME = "debug-artifacts";
|
||||
|
||||
/**
|
||||
* Default name of the database in the debugging artifact.
|
||||
*/
|
||||
export const DEFAULT_DEBUG_DATABASE_NAME = "db";
|
||||
|
||||
/**
|
||||
* Get the extra options for the codeql commands.
|
||||
@@ -559,13 +564,11 @@ export async function codeQlVersionAbove(
|
||||
export async function bundleDb(
|
||||
config: Config,
|
||||
language: Language,
|
||||
codeql: CodeQL
|
||||
codeql: CodeQL,
|
||||
dbName: string
|
||||
) {
|
||||
const databasePath = getCodeQLDatabasePath(config, language);
|
||||
const databaseBundlePath = path.resolve(
|
||||
config.dbLocation,
|
||||
`${databasePath}.zip`
|
||||
);
|
||||
const databaseBundlePath = path.resolve(config.dbLocation, `${dbName}.zip`);
|
||||
// For a tiny bit of added safety, delete the file if it exists.
|
||||
// The file is probably from an earlier call to this function, either
|
||||
// as part of this action step or a previous one, but it could also be
|
||||
@@ -574,7 +577,7 @@ export async function bundleDb(
|
||||
if (fs.existsSync(databaseBundlePath)) {
|
||||
await del(databaseBundlePath, { force: true });
|
||||
}
|
||||
await codeql.databaseBundle(databasePath, databaseBundlePath);
|
||||
await codeql.databaseBundle(databasePath, databaseBundlePath, dbName);
|
||||
return databaseBundlePath;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user