As we move towards analysing the merge commit for pull requests by default, we should stop sending `/refs/pull/n/head` rather than `refs/pull/n/merge` _unless_ the checked-out SHA has actually changed. Here we assume that any change (compared to GITHUB_SHA) indicates that `git checkout HEAD^2` has been run earlier. This may sometimes be incorrect (e.g. `git checkout mybranch`), but in that case the ref would be wrong either way.
97 lines
2.8 KiB
TypeScript
97 lines
2.8 KiB
TypeScript
import * as core from "@actions/core";
|
|
|
|
import * as actionsUtil from "./actions-util";
|
|
import { AnalysisStatusReport, runAnalyze } from "./analyze";
|
|
import { getConfig } from "./config-utils";
|
|
import { getActionsLogger } from "./logging";
|
|
import { parseRepositoryNwo } from "./repository";
|
|
import * as util from "./util";
|
|
|
|
interface FinishStatusReport
|
|
extends actionsUtil.StatusReportBase,
|
|
AnalysisStatusReport {}
|
|
|
|
async function sendStatusReport(
|
|
startedAt: Date,
|
|
stats: AnalysisStatusReport | undefined,
|
|
error?: Error
|
|
) {
|
|
const status =
|
|
stats?.analyze_failure_language !== undefined || error !== undefined
|
|
? "failure"
|
|
: "success";
|
|
const statusReportBase = await actionsUtil.createStatusReportBase(
|
|
"finish",
|
|
status,
|
|
startedAt,
|
|
error?.message,
|
|
error?.stack
|
|
);
|
|
const statusReport: FinishStatusReport = {
|
|
...statusReportBase,
|
|
...(stats || {}),
|
|
};
|
|
await actionsUtil.sendStatusReport(statusReport);
|
|
}
|
|
|
|
async function run() {
|
|
const startedAt = new Date();
|
|
let stats: AnalysisStatusReport | undefined = undefined;
|
|
try {
|
|
actionsUtil.prepareLocalRunEnvironment();
|
|
if (
|
|
!(await actionsUtil.sendStatusReport(
|
|
await actionsUtil.createStatusReportBase(
|
|
"finish",
|
|
"starting",
|
|
startedAt
|
|
),
|
|
true
|
|
))
|
|
) {
|
|
return;
|
|
}
|
|
const logger = getActionsLogger();
|
|
const config = await getConfig(
|
|
actionsUtil.getRequiredEnvParam("RUNNER_TEMP"),
|
|
logger
|
|
);
|
|
if (config === undefined) {
|
|
throw new Error(
|
|
"Config file could not be found at expected location. Has the 'init' action been called?"
|
|
);
|
|
}
|
|
stats = await runAnalyze(
|
|
parseRepositoryNwo(actionsUtil.getRequiredEnvParam("GITHUB_REPOSITORY")),
|
|
await actionsUtil.getCommitOid(),
|
|
await actionsUtil.getRef(),
|
|
await actionsUtil.getAnalysisKey(),
|
|
actionsUtil.getRequiredEnvParam("GITHUB_WORKFLOW"),
|
|
actionsUtil.getWorkflowRunID(),
|
|
actionsUtil.getRequiredInput("checkout_path"),
|
|
actionsUtil.getRequiredInput("matrix"),
|
|
actionsUtil.getRequiredInput("token"),
|
|
actionsUtil.getRequiredEnvParam("GITHUB_SERVER_URL"),
|
|
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
|
|
);
|
|
} catch (error) {
|
|
core.setFailed(error.message);
|
|
console.log(error);
|
|
await sendStatusReport(startedAt, stats, error);
|
|
return;
|
|
}
|
|
|
|
await sendStatusReport(startedAt, stats);
|
|
}
|
|
|
|
run().catch((e) => {
|
|
core.setFailed(`analyze action failed: ${e}`);
|
|
console.log(e);
|
|
});
|