Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improve docs and method naming
  • Loading branch information
henrymercer committed Sep 17, 2024
commit 78d398ebc6be2d0a1fb3c058f572b35b95ffe13d
31 changes: 18 additions & 13 deletions lib/debug-artifacts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/debug-artifacts.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 24 additions & 17 deletions src/debug-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export async function uploadCombinedSarifArtifacts() {
}

/**
* Try to get the SARIF result path for the given language.
* Try to prepare a SARIF result debug artifact for the given language.
*
* If an error occurs, log it and return an empty list.
* @return The path to that debug artifact, or undefined if an error occurs.
*/
function tryGetSarifResultPath(
function tryPrepareSarifDebugArtifact(
config: Config,
language: Language,
logger: Logger,
): string[] {
): string | undefined {
try {
const analyzeActionOutputDir = process.env[EnvVar.SARIF_RESULTS_OUTPUT_DIR];
if (
Expand All @@ -94,7 +94,7 @@ function tryGetSarifResultPath(
`${language}.sarif`,
);
fs.copyFileSync(sarifFile, sarifInDbLocation);
return [sarifInDbLocation];
return sarifInDbLocation;
}
}
} catch (e) {
Expand All @@ -104,39 +104,38 @@ function tryGetSarifResultPath(
)}`,
);
}
return [];
return undefined;
}

/**
* Try to bundle the database for the given language. Return a list containing
* the path to the database bundle.
* Try to bundle the database for the given language.
*
* If an error occurs, log it and return an empty list.
* @return The path to the database bundle, or undefined if an error occurs.
*/
async function tryBundleDatabase(
config: Config,
language: Language,
logger: Logger,
): Promise<string[]> {
): Promise<string | undefined> {
try {
if (dbIsFinalized(config, language, logger)) {
try {
return [await createDatabaseBundleCli(config, language)];
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: ${getErrorMessage(e)}`,
);
}
}
return [await createPartialDatabaseBundle(config, language)];
return await createPartialDatabaseBundle(config, language);
} catch (e) {
logger.warning(
`Failed to bundle database for ${language}. Reason: ${getErrorMessage(
e,
)}`,
);
return [];
return undefined;
}
}

Expand All @@ -153,7 +152,14 @@ export async function tryUploadAllAvailableDebugArtifacts(
const filesToUpload: string[] = [];

for (const language of config.languages) {
filesToUpload.push(...tryGetSarifResultPath(config, language, logger));
const sarifResultDebugArtifact = tryPrepareSarifDebugArtifact(
config,
language,
logger,
);
if (sarifResultDebugArtifact) {
filesToUpload.push(sarifResultDebugArtifact);
}

// Add any log files
const databaseDirectory = getCodeQLDatabasePath(config, language);
Expand All @@ -172,9 +178,10 @@ export async function tryUploadAllAvailableDebugArtifacts(
}

// Add database bundle
filesToUpload.push(
...(await tryBundleDatabase(config, language, logger)),
);
const databaseBundle = await tryBundleDatabase(config, language, logger);
if (databaseBundle) {
filesToUpload.push(databaseBundle);
}
Comment thread
henrymercer marked this conversation as resolved.
Outdated
}

await uploadDebugArtifacts(
Expand Down