Skip to content

Commit

Permalink
Address more PR comments, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Angela P Wen committed Aug 2, 2022
1 parent 44a27e6 commit 5895ab0
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 57 deletions.
36 changes: 21 additions & 15 deletions lib/actions-util.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/actions-util.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/analyze-action-post.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/analyze-action-post.js.map

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

5 changes: 2 additions & 3 deletions lib/init-action-post.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/init-action-post.js.map

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

66 changes: 36 additions & 30 deletions src/actions-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
listFolder,
UserError,
} from "./util";
import { Language } from "./languages";

// eslint-disable-next-line import/no-commonjs
const pkg = require("../package.json");
Expand Down Expand Up @@ -1006,48 +1007,53 @@ export async function uploadLogsDebugArtifact(config: Config) {
}
}

/**
* If a database has not been finalized, we cannot run the `codeql database bundle`
* command in the CLI because it will return an error. Instead we directly zip
* all files in the database folder and upload it as an artifact.
*/
async function uploadPartialDatabaseBundle(config: Config, language: Language) {
const databasePath = getCodeQLDatabasePath(config, language);
const databaseBundlePath = path.resolve(
config.dbLocation,
`${config.debugDatabaseName}-${language}-partial.zip`
);
core.info(
`${config.debugDatabaseName}-${language} is not finalized. Uploading partial database bundle at ${databaseBundlePath}...`
);
// See `bundleDb` for explanation behind deleting existing db bundle.
if (fs.existsSync(databaseBundlePath)) {
await del(databaseBundlePath, { force: true });
}
const zip = new AdmZip();
zip.addLocalFolder(databasePath);
zip.writeZip(databaseBundlePath);
await uploadDebugArtifacts(
[databaseBundlePath],
config.dbLocation,
config.debugArtifactName
);
}

export async function uploadDatabaseBundleDebugArtifact(
config: Config,
logger: Logger
) {
for (const language of config.languages) {
if (!dbIsFinalized(config, language, logger)) {
// Zip up files and upload directly.
const databasePath = getCodeQLDatabasePath(config, language);
const databaseBundlePath = path.resolve(
config.dbLocation,
`${config.debugDatabaseName}-${language}-partial.zip`
);
core.info(
`${config.debugDatabaseName}-${language} is not finalized. Uploading partial database bundle at ${databaseBundlePath}...`
);
// See `bundleDb` for explanation behind deleting existing db bundle.
if (fs.existsSync(databaseBundlePath)) {
await del(databaseBundlePath, { force: true });
}
const zip = new AdmZip();
zip.addLocalFolder(databasePath);
zip.writeZip(databaseBundlePath);
await uploadDebugArtifacts(
[databaseBundlePath],
config.dbLocation,
config.debugArtifactName
);
await uploadPartialDatabaseBundle(config, language);
continue;
}
try {
// Otherwise run `codeql database bundle` command.
const toUpload: string[] = [];
toUpload.push(
await bundleDb(
config,
language,
await getCodeQL(config.codeQLCmd),
`${config.debugDatabaseName}-${language}`
)
const bundlePath = await bundleDb(
config,
language,
await getCodeQL(config.codeQLCmd),
`${config.debugDatabaseName}-${language}`
);
await uploadDebugArtifacts(
toUpload,
[bundlePath],
config.dbLocation,
config.debugArtifactName
);
Expand Down
2 changes: 1 addition & 1 deletion src/analyze-action-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function run(uploadSarifDebugArtifact: Function) {
const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger);
if (config === undefined) {
throw new Error(
"Config file could not be found at expected location. Has the 'init' action been called?"
"Config file could not be found at expected location. Did the 'init' action fail to start?"
);
}

Expand Down
7 changes: 3 additions & 4 deletions src/init-action-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as core from "@actions/core";

import * as actionsUtil from "./actions-util";
import { Config, getConfig } from "./config-utils";
import { getConfig } from "./config-utils";
import { getActionsLogger } from "./logging";

async function run(
Expand All @@ -17,11 +17,10 @@ async function run(
) {
const logger = getActionsLogger();

let config: Config | undefined = undefined;
config = await getConfig(actionsUtil.getTemporaryDirectory(), logger);
const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger);
if (config === undefined) {
throw new Error(
"Config file could not be found at expected location. Has the 'init' action been called?"
"Config file could not be found at expected location. Did the 'init' action fail to start?"
);
}

Expand Down

0 comments on commit 5895ab0

Please sign in to comment.