Skip to content

Improve the robustness of creating and uploading debug artifacts #2486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 17, 2024
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
Handle CLI errors when creating debug artifacts
  • Loading branch information
henrymercer committed Sep 16, 2024
commit d061f2cdd00f958f7237a3359efb9b922c520f9a
49 changes: 32 additions & 17 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.

67 changes: 49 additions & 18 deletions src/debug-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
doesDirectoryExist,
getCodeQLDatabasePath,
listFolder,
wrapError,
} from "./util";

export function sanitizeArifactName(name: string): string {
Expand Down Expand Up @@ -65,34 +66,70 @@ export async function uploadCombinedSarifArtifacts() {
}
}

export async function uploadAllAvailableDebugArtifacts(
function tryGetSarifResultPath(
config: Config,
language: Language,
logger: Logger,
) {
const filesToUpload: string[] = [];

const analyzeActionOutputDir = process.env[EnvVar.SARIF_RESULTS_OUTPUT_DIR];
for (const lang of config.languages) {
// Add any SARIF files, if they exist
): string[] {
try {
const analyzeActionOutputDir = process.env[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`,
`${language}.sarif`,
);
fs.copyFileSync(sarifFile, sarifInDbLocation);
filesToUpload.push(sarifInDbLocation);
return [sarifInDbLocation];
}
}
} catch (e) {
logger.warning(
`Failed to find SARIF results path for ${language}. ${wrapError(e)}`,
);
}
return [];
}

async function tryBundleDatabase(
config: Config,
language: Language,
logger: Logger,
): Promise<string[]> {
try {
if (!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}. ${wrapError(e)}`,
);
return [];
}
}

export async function uploadAllAvailableDebugArtifacts(
config: Config,
logger: Logger,
) {
const filesToUpload: string[] = [];

for (const language of config.languages) {
filesToUpload.push(...tryGetSarifResultPath(config, language, logger));

// Add any log files
const databaseDirectory = getCodeQLDatabasePath(config, lang);
const databaseDirectory = getCodeQLDatabasePath(config, language);
const logsDirectory = path.resolve(databaseDirectory, "log");
if (doesDirectoryExist(logsDirectory)) {
filesToUpload.push(...listFolder(logsDirectory));
Expand All @@ -108,13 +145,7 @@ export async function uploadAllAvailableDebugArtifacts(
}

// Add database bundle
let databaseBundlePath: string;
if (!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(
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy