Catch case where database isn't finalized

This commit is contained in:
Angela P Wen 2022-07-29 12:00:07 +02:00
parent 1016eba538
commit 2746051310
12 changed files with 70 additions and 64 deletions

View file

@ -9,11 +9,8 @@ import * as safeWhich from "@chrisgavin/safe-which";
import * as yaml from "js-yaml";
import * as api from "./api-client";
import { getCodeQL } from "./codeql";
import { Config } from "./config-utils";
import * as sharedEnv from "./shared-environment";
import {
bundleDb,
getCachedCodeQlVersion,
getRequiredEnvParam,
GITHUB_DOTCOM_URL,
@ -910,28 +907,3 @@ export async function uploadDebugArtifacts(
path.normalize(rootDir)
);
}
// TODO(angelapwen): this method doesn't work yet for incomplete database
// bundles. Move caller to init-action-cleanup after implementation.
export async function uploadDatabaseBundleDebugArtifact(config: Config) {
try {
const toUpload: string[] = [];
for (const language of config.languages) {
toUpload.push(
await bundleDb(
config,
language,
await getCodeQL(config.codeQLCmd),
`${config.debugDatabaseName}-${language}`
)
);
}
await uploadDebugArtifacts(
toUpload,
config.dbLocation,
config.debugArtifactName
);
} catch (error) {
console.log(`Failed to upload database debug bundles: ${error}`);
}
}

View file

@ -188,10 +188,6 @@ async function run() {
}
return;
} finally {
if (config?.debugMode) {
await actionsUtil.uploadDatabaseBundleDebugArtifact(config);
}
}
if (runStats && uploadResult) {

View file

@ -147,7 +147,7 @@ export async function createdDBForScannedLanguages(
}
}
function dbIsFinalized(
export function dbIsFinalized(
config: configUtils.Config,
language: Language,
logger: Logger

View file

@ -4,10 +4,11 @@ import * as path from "path";
import * as core from "@actions/core";
import * as actionsUtil from "./actions-util";
import { dbIsFinalized } from "./analyze";
import { CODEQL_VERSION_NEW_TRACING, getCodeQL } from "./codeql";
import { Config, getConfig } from "./config-utils";
import { getActionsLogger } from "./logging";
import { codeQlVersionAbove, getCodeQLDatabasePath } from "./util";
import { getActionsLogger, Logger } from "./logging";
import { bundleDb, codeQlVersionAbove, getCodeQLDatabasePath } from "./util";
function listFolder(dir: string): string[] {
const entries = fs.readdirSync(dir, { withFileTypes: true });
@ -22,6 +23,42 @@ function listFolder(dir: string): string[] {
return files;
}
export async function uploadDatabaseBundleDebugArtifact(
config: Config,
logger: Logger
) {
for (const language of config.languages) {
if (!dbIsFinalized(config, language, logger)) {
core.info(
`${config.debugDatabaseName}-${language} is not finalized. Uploading partial database bundle...`
);
// TODO(angelapwen): Zip up files and upload directly.
continue;
}
try {
// Otherwise run `codeql database bundle` command.
const toUpload: string[] = [];
toUpload.push(
await bundleDb(
config,
language,
await getCodeQL(config.codeQLCmd),
`${config.debugDatabaseName}-${language}`
)
);
await actionsUtil.uploadDebugArtifacts(
toUpload,
config.dbLocation,
config.debugArtifactName
);
} catch (error) {
core.info(
`Failed to upload database debug bundles for ${config.debugDatabaseName}-${language}: ${error}`
);
}
}
}
async function uploadLogsDebugArtifact(config: Config) {
const codeql = await getCodeQL(config.codeQLCmd);
@ -108,9 +145,9 @@ async function run() {
// Upload appropriate Actions artifacts for debugging
if (config?.debugMode) {
await uploadDatabaseBundleDebugArtifact(config, logger);
await uploadLogsDebugArtifact(config);
await uploadFinalLogsDebugArtifact(config);
// TODO(angelapwen): Add database bundle upload.
}
}