Fall back to partial database bundle if CLI command fails

This commit is contained in:
Henry Mercer 2024-09-16 22:29:11 +02:00
parent 80d7a6c8d4
commit bbd7c801a0
3 changed files with 34 additions and 20 deletions

23
lib/debug-artifacts.js generated
View file

@ -87,21 +87,25 @@ function tryGetSarifResultPath(config, language, logger) {
}
}
catch (e) {
logger.warning(`Failed to find SARIF results path for ${language}. ${(0, util_1.wrapError)(e).message}`);
logger.warning(`Failed to find SARIF results path for ${language}. Reason: ${(0, util_1.wrapError)(e).message}`);
}
return [];
}
async function tryBundleDatabase(config, language, logger) {
try {
if (!(0, analyze_1.dbIsFinalized)(config, language, logger)) {
return [await createPartialDatabaseBundle(config, language)];
}
else {
return [await createDatabaseBundleCli(config, language)];
if ((0, analyze_1.dbIsFinalized)(config, language, logger)) {
try {
return [await createDatabaseBundleCli(config, language)];
}
catch (e) {
logger.warning(`Failed to bundle database for ${language} using the CLI. ` +
`Falling back to a partial bundle. Reason: ${(0, util_1.wrapError)(e).message}`);
}
}
return [await createPartialDatabaseBundle(config, language)];
}
catch (e) {
logger.warning(`Failed to bundle database for ${language}. ${(0, util_1.wrapError)(e).message}`);
logger.warning(`Failed to bundle database for ${language}. Reason: ${(0, util_1.wrapError)(e).message}`);
return [];
}
}
@ -127,7 +131,7 @@ async function uploadAllAvailableDebugArtifacts(config, logger) {
await uploadDebugArtifacts(filesToUpload, config.dbLocation, config.debugArtifactName);
}
catch (e) {
logger.warning(`Failed to upload debug artifacts: ${(0, util_1.wrapError)(e).message}`);
logger.warning(`Failed to upload debug artifacts. Reason: ${(0, util_1.wrapError)(e).message}`);
}
}
async function uploadDebugArtifacts(toUpload, rootDir, artifactName) {
@ -154,7 +158,7 @@ async function uploadDebugArtifacts(toUpload, rootDir, artifactName) {
}
catch (e) {
// A failure to upload debug artifacts should not fail the entire action.
core.warning(`Failed to upload debug artifacts: ${e}`);
core.warning(`Failed to upload debug artifacts. Reason: ${(0, util_1.wrapError)(e).message}`);
}
}
/**
@ -179,7 +183,6 @@ async function createPartialDatabaseBundle(config, language) {
* 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;
}