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.
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
import * as core from "@actions/core";
|
|
|
|
import * as actionsUtil from "./actions-util";
|
|
import { getActionsLogger } from "./logging";
|
|
import { parseRepositoryNwo } from "./repository";
|
|
import * as upload_lib from "./upload-lib";
|
|
|
|
interface UploadSarifStatusReport
|
|
extends actionsUtil.StatusReportBase,
|
|
upload_lib.UploadStatusReport {}
|
|
|
|
async function sendSuccessStatusReport(
|
|
startedAt: Date,
|
|
uploadStats: upload_lib.UploadStatusReport
|
|
) {
|
|
const statusReportBase = await actionsUtil.createStatusReportBase(
|
|
"upload-sarif",
|
|
"success",
|
|
startedAt
|
|
);
|
|
const statusReport: UploadSarifStatusReport = {
|
|
...statusReportBase,
|
|
...uploadStats,
|
|
};
|
|
await actionsUtil.sendStatusReport(statusReport);
|
|
}
|
|
|
|
async function run() {
|
|
const startedAt = new Date();
|
|
if (
|
|
!(await actionsUtil.sendStatusReport(
|
|
await actionsUtil.createStatusReportBase(
|
|
"upload-sarif",
|
|
"starting",
|
|
startedAt
|
|
),
|
|
true
|
|
))
|
|
) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const uploadStats = await upload_lib.upload(
|
|
actionsUtil.getRequiredInput("sarif_file"),
|
|
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"),
|
|
"actions",
|
|
getActionsLogger()
|
|
);
|
|
await sendSuccessStatusReport(startedAt, uploadStats);
|
|
} catch (error) {
|
|
core.setFailed(error.message);
|
|
console.log(error);
|
|
await actionsUtil.sendStatusReport(
|
|
await actionsUtil.createStatusReportBase(
|
|
"upload-sarif",
|
|
"failure",
|
|
startedAt,
|
|
error.message,
|
|
error.stack
|
|
)
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
|
|
run().catch((e) => {
|
|
core.setFailed(`codeql/upload-sarif action failed: ${e}`);
|
|
console.log(e);
|
|
});
|