Handle CLI errors when creating debug artifacts
This commit is contained in:
parent
5618c9fc1e
commit
d061f2cdd0
3 changed files with 91 additions and 45 deletions
49
lib/debug-artifacts.js
generated
49
lib/debug-artifacts.js
generated
|
|
@ -71,24 +71,46 @@ async function uploadCombinedSarifArtifacts() {
|
|||
}
|
||||
}
|
||||
}
|
||||
async function uploadAllAvailableDebugArtifacts(config, logger) {
|
||||
const filesToUpload = [];
|
||||
const analyzeActionOutputDir = process.env[environment_1.EnvVar.SARIF_RESULTS_OUTPUT_DIR];
|
||||
for (const lang of config.languages) {
|
||||
// Add any SARIF files, if they exist
|
||||
function tryGetSarifResultPath(config, language, logger) {
|
||||
try {
|
||||
const analyzeActionOutputDir = process.env[environment_1.EnvVar.SARIF_RESULTS_OUTPUT_DIR];
|
||||
if (analyzeActionOutputDir !== undefined &&
|
||||
fs.existsSync(analyzeActionOutputDir) &&
|
||||
fs.lstatSync(analyzeActionOutputDir).isDirectory()) {
|
||||
const sarifFile = path.resolve(analyzeActionOutputDir, `${lang}.sarif`);
|
||||
const sarifFile = path.resolve(analyzeActionOutputDir, `${language}.sarif`);
|
||||
// Move SARIF to DB location so that they can be uploaded with the same root directory as the other artifacts.
|
||||
if (fs.existsSync(sarifFile)) {
|
||||
const sarifInDbLocation = path.resolve(config.dbLocation, `${lang}.sarif`);
|
||||
const sarifInDbLocation = path.resolve(config.dbLocation, `${language}.sarif`);
|
||||
fs.copyFileSync(sarifFile, sarifInDbLocation);
|
||||
filesToUpload.push(sarifInDbLocation);
|
||||
return [sarifInDbLocation];
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to find SARIF results path for ${language}. ${(0, util_1.wrapError)(e)}`);
|
||||
}
|
||||
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)];
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Failed to bundle database for ${language}. ${(0, util_1.wrapError)(e)}`);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
async function uploadAllAvailableDebugArtifacts(config, logger) {
|
||||
const filesToUpload = [];
|
||||
for (const language of config.languages) {
|
||||
filesToUpload.push(...tryGetSarifResultPath(config, language, logger));
|
||||
// Add any log files
|
||||
const databaseDirectory = (0, util_1.getCodeQLDatabasePath)(config, lang);
|
||||
const databaseDirectory = (0, util_1.getCodeQLDatabasePath)(config, language);
|
||||
const logsDirectory = path.resolve(databaseDirectory, "log");
|
||||
if ((0, util_1.doesDirectoryExist)(logsDirectory)) {
|
||||
filesToUpload.push(...(0, util_1.listFolder)(logsDirectory));
|
||||
|
|
@ -99,14 +121,7 @@ async function uploadAllAvailableDebugArtifacts(config, logger) {
|
|||
filesToUpload.push(...(0, util_1.listFolder)(multiLanguageTracingLogsDirectory));
|
||||
}
|
||||
// Add database bundle
|
||||
let databaseBundlePath;
|
||||
if (!(0, analyze_1.dbIsFinalized)(config, lang, logger)) {
|
||||
databaseBundlePath = await createPartialDatabaseBundle(config, lang);
|
||||
}
|
||||
else {
|
||||
databaseBundlePath = await createDatabaseBundleCli(config, lang);
|
||||
}
|
||||
filesToUpload.push(databaseBundlePath);
|
||||
filesToUpload.push(...(await tryBundleDatabase(config, language, logger)));
|
||||
}
|
||||
await uploadDebugArtifacts(filesToUpload, config.dbLocation, config.debugArtifactName);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue