Address review comments

This commit is contained in:
Angela P Wen
2022-08-11 13:45:26 +02:00
parent 3c4f458a1a
commit 65d6ee0c51
16 changed files with 126 additions and 107 deletions

31
lib/debug-artifacts.js generated
View File

@@ -99,9 +99,9 @@ exports.uploadLogsDebugArtifact = uploadLogsDebugArtifact;
/**
* If a database has not been finalized, we cannot run the `codeql database bundle`
* command in the CLI because it will return an error. Instead we directly zip
* all files in the database folder and upload it as an artifact.
* all files in the database folder and return the path.
*/
async function uploadPartialDatabaseBundle(config, language) {
async function createPartialDatabaseBundle(config, language) {
const databasePath = (0, util_1.getCodeQLDatabasePath)(config, language);
const databaseBundlePath = path.resolve(config.dbLocation, `${config.debugDatabaseName}-${language}-partial.zip`);
core.info(`${config.debugDatabaseName}-${language} is not finalized. Uploading partial database bundle at ${databaseBundlePath}...`);
@@ -112,21 +112,30 @@ async function uploadPartialDatabaseBundle(config, language) {
const zip = new adm_zip_1.default();
zip.addLocalFolder(databasePath);
zip.writeZip(databaseBundlePath);
await uploadDebugArtifacts([databaseBundlePath], config.dbLocation, config.debugArtifactName);
return databaseBundlePath;
}
/**
* Runs `codeql database bundle` command and returns the path.
*/
async function createDatabaseBundleCli(config, language) {
// Otherwise run `codeql database bundle` command.
const databaseBundlePath = await (0, util_1.bundleDb)(config, language, await (0, codeql_1.getCodeQL)(config.codeQLCmd), `${config.debugDatabaseName}-${language}`);
return databaseBundlePath;
}
async function uploadDatabaseBundleDebugArtifact(config, logger) {
for (const language of config.languages) {
if (!(0, analyze_1.dbIsFinalized)(config, language, logger)) {
await uploadPartialDatabaseBundle(config, language);
continue;
}
try {
// Otherwise run `codeql database bundle` command.
const bundlePath = await (0, util_1.bundleDb)(config, language, await (0, codeql_1.getCodeQL)(config.codeQLCmd), `${config.debugDatabaseName}-${language}`);
await uploadDebugArtifacts([bundlePath], config.dbLocation, config.debugArtifactName);
let databaseBundlePath;
if (!(0, analyze_1.dbIsFinalized)(config, language, logger)) {
databaseBundlePath = await createPartialDatabaseBundle(config, language);
}
else {
databaseBundlePath = await createDatabaseBundleCli(config, language);
}
await uploadDebugArtifacts([databaseBundlePath], config.dbLocation, config.debugArtifactName);
}
catch (error) {
core.info(`Failed to upload database debug bundles for ${config.debugDatabaseName}-${language}: ${error}`);
core.info(`Failed to upload database debug bundle for ${config.debugDatabaseName}-${language}: ${error}`);
}
}
}