Move uploading side-effect out of runAnalyze
https://github.com/github/codeql-action/pull/323#discussion_r530978010
This commit is contained in:
parent
9532bda6e4
commit
ff28c8d403
9 changed files with 57 additions and 90 deletions
|
|
@ -9,6 +9,7 @@ import {
|
|||
import { getConfig } from "./config-utils";
|
||||
import { getActionsLogger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
import * as util from "./util";
|
||||
|
||||
interface FinishStatusReport
|
||||
|
|
@ -68,7 +69,23 @@ async function run() {
|
|||
auth: actionsUtil.getRequiredInput("token"),
|
||||
url: actionsUtil.getRequiredEnvParam("GITHUB_SERVER_URL"),
|
||||
};
|
||||
stats = await runAnalyze(
|
||||
const outputDir = actionsUtil.getRequiredInput("output");
|
||||
const queriesStats = await runAnalyze(
|
||||
outputDir,
|
||||
util.getMemoryFlag(actionsUtil.getOptionalInput("ram")),
|
||||
util.getAddSnippetsFlag(actionsUtil.getRequiredInput("add-snippets")),
|
||||
util.getThreadsFlag(actionsUtil.getOptionalInput("threads"), logger),
|
||||
config,
|
||||
logger
|
||||
);
|
||||
|
||||
if (actionsUtil.getRequiredInput("upload") !== "true") {
|
||||
logger.info("Not uploading results");
|
||||
return;
|
||||
}
|
||||
|
||||
const uploadStats = await upload_lib.uploadFromActions(
|
||||
outputDir,
|
||||
parseRepositoryNwo(actionsUtil.getRequiredEnvParam("GITHUB_REPOSITORY")),
|
||||
await actionsUtil.getCommitOid(),
|
||||
await actionsUtil.getRef(),
|
||||
|
|
@ -78,15 +95,10 @@ async function run() {
|
|||
actionsUtil.getRequiredInput("checkout_path"),
|
||||
actionsUtil.getRequiredInput("matrix"),
|
||||
apiDetails,
|
||||
actionsUtil.getRequiredInput("upload") === "true",
|
||||
"actions",
|
||||
actionsUtil.getRequiredInput("output"),
|
||||
util.getMemoryFlag(actionsUtil.getOptionalInput("ram")),
|
||||
util.getAddSnippetsFlag(actionsUtil.getRequiredInput("add-snippets")),
|
||||
util.getThreadsFlag(actionsUtil.getOptionalInput("threads"), logger),
|
||||
config,
|
||||
logger
|
||||
);
|
||||
stats = { ...queriesStats, ...uploadStats };
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
console.log(error);
|
||||
|
|
|
|||
|
|
@ -4,12 +4,10 @@ import * as path from "path";
|
|||
import * as toolrunner from "@actions/exec/lib/toolrunner";
|
||||
|
||||
import * as analysisPaths from "./analysis-paths";
|
||||
import { GitHubApiDetails } from "./api-client";
|
||||
import { getCodeQL } from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { isScannedLanguage, Language } from "./languages";
|
||||
import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import * as sharedEnv from "./shared-environment";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
import * as util from "./util";
|
||||
|
|
@ -217,24 +215,13 @@ export async function runQueries(
|
|||
}
|
||||
|
||||
export async function runAnalyze(
|
||||
repositoryNwo: RepositoryNwo,
|
||||
commitOid: string,
|
||||
ref: string,
|
||||
analysisKey: string | undefined,
|
||||
analysisName: string | undefined,
|
||||
workflowRunID: number | undefined,
|
||||
checkoutPath: string,
|
||||
environment: string | undefined,
|
||||
apiDetails: GitHubApiDetails,
|
||||
doUpload: boolean,
|
||||
mode: util.Mode,
|
||||
outputDir: string,
|
||||
memoryFlag: string,
|
||||
addSnippetsFlag: string,
|
||||
threadsFlag: string,
|
||||
config: configUtils.Config,
|
||||
logger: Logger
|
||||
): Promise<AnalysisStatusReport> {
|
||||
): Promise<QueriesStatusReport> {
|
||||
// Delete the tracer config env var to avoid tracing ourselves
|
||||
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
|
||||
|
||||
|
|
@ -253,39 +240,5 @@ export async function runAnalyze(
|
|||
logger
|
||||
);
|
||||
|
||||
if (!doUpload) {
|
||||
logger.info("Not uploading results");
|
||||
return { ...queriesStats };
|
||||
}
|
||||
|
||||
let uploadStats: upload_lib.UploadStatusReport;
|
||||
if (mode === "actions") {
|
||||
uploadStats = await upload_lib.uploadFromActions(
|
||||
outputDir,
|
||||
repositoryNwo,
|
||||
commitOid,
|
||||
ref,
|
||||
analysisKey!,
|
||||
analysisName!,
|
||||
workflowRunID!,
|
||||
checkoutPath,
|
||||
environment!,
|
||||
apiDetails,
|
||||
logger
|
||||
);
|
||||
} else if (mode === "runner") {
|
||||
uploadStats = await upload_lib.uploadFromRunner(
|
||||
outputDir,
|
||||
repositoryNwo,
|
||||
commitOid,
|
||||
ref,
|
||||
checkoutPath,
|
||||
apiDetails,
|
||||
logger
|
||||
);
|
||||
} else {
|
||||
throw new Error(`Unknown mode "${mode}"`);
|
||||
}
|
||||
|
||||
return { ...queriesStats, ...uploadStats };
|
||||
return { ...queriesStats };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -372,17 +372,6 @@ program
|
|||
};
|
||||
|
||||
await runAnalyze(
|
||||
parseRepositoryNwo(cmd.repository),
|
||||
cmd.commit,
|
||||
parseRef(cmd.ref),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
cmd.checkoutPath || process.cwd(),
|
||||
undefined,
|
||||
apiDetails,
|
||||
cmd.upload,
|
||||
"runner",
|
||||
outputDir,
|
||||
getMemoryFlag(cmd.ram),
|
||||
getAddSnippetsFlag(cmd.addSnippets),
|
||||
|
|
@ -390,6 +379,21 @@ program
|
|||
config,
|
||||
logger
|
||||
);
|
||||
|
||||
if (!cmd.upload) {
|
||||
logger.info("Not uploading results");
|
||||
return;
|
||||
}
|
||||
|
||||
await upload_lib.uploadFromRunner(
|
||||
outputDir,
|
||||
parseRepositoryNwo(cmd.repository),
|
||||
cmd.commit,
|
||||
parseRef(cmd.ref),
|
||||
cmd.checkoutPath || process.cwd(),
|
||||
apiDetails,
|
||||
logger
|
||||
);
|
||||
} catch (e) {
|
||||
logger.error("Analyze failed");
|
||||
logger.error(e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue