mirror of
https://github.com/github/codeql-action.git
synced 2026-01-02 12:40:21 +08:00
Remove dead guard for GHES 3.0
This commit is contained in:
@@ -262,11 +262,7 @@ async function run() {
|
||||
core.setOutput("db-locations", dbLocations);
|
||||
|
||||
if (runStats && actionsUtil.getRequiredInput("upload") === "true") {
|
||||
uploadResult = await upload_lib.uploadFromActions(
|
||||
outputDir,
|
||||
config.gitHubVersion,
|
||||
logger
|
||||
);
|
||||
uploadResult = await upload_lib.uploadFromActions(outputDir, logger);
|
||||
core.setOutput("sarif-id", uploadResult.sarifID);
|
||||
} else {
|
||||
logger.info("Not uploading results");
|
||||
|
||||
@@ -7,13 +7,7 @@ import { getRunnerLogger, Logger } from "./logging";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import * as uploadLib from "./upload-lib";
|
||||
import { pruneInvalidResults } from "./upload-lib";
|
||||
import {
|
||||
GitHubVariant,
|
||||
GitHubVersion,
|
||||
initializeEnvironment,
|
||||
SarifFile,
|
||||
withTmpDir,
|
||||
} from "./util";
|
||||
import { initializeEnvironment, SarifFile, withTmpDir } from "./util";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
@@ -35,36 +29,23 @@ test("validateSarifFileSchema - invalid", (t) => {
|
||||
);
|
||||
});
|
||||
|
||||
test("validate correct payload used per version", async (t) => {
|
||||
const newVersions: GitHubVersion[] = [
|
||||
{ type: GitHubVariant.DOTCOM },
|
||||
{ type: GitHubVariant.GHES, version: "3.1.0" },
|
||||
];
|
||||
const oldVersions: GitHubVersion[] = [
|
||||
{ type: GitHubVariant.GHES, version: "2.22.1" },
|
||||
{ type: GitHubVariant.GHES, version: "3.0.0" },
|
||||
];
|
||||
const allVersions = newVersions.concat(oldVersions);
|
||||
|
||||
test("validate correct payload used for push, PR merge commit, and PR head", async (t) => {
|
||||
process.env["GITHUB_EVENT_NAME"] = "push";
|
||||
for (const version of allVersions) {
|
||||
const payload: any = uploadLib.buildPayload(
|
||||
"commit",
|
||||
"refs/heads/master",
|
||||
"key",
|
||||
undefined,
|
||||
"",
|
||||
undefined,
|
||||
"/opt/src",
|
||||
undefined,
|
||||
["CodeQL", "eslint"],
|
||||
version,
|
||||
"mergeBaseCommit"
|
||||
);
|
||||
// Not triggered by a pull request
|
||||
t.falsy(payload.base_ref);
|
||||
t.falsy(payload.base_sha);
|
||||
}
|
||||
const pushPayload: any = uploadLib.buildPayload(
|
||||
"commit",
|
||||
"refs/heads/master",
|
||||
"key",
|
||||
undefined,
|
||||
"",
|
||||
undefined,
|
||||
"/opt/src",
|
||||
undefined,
|
||||
["CodeQL", "eslint"],
|
||||
"mergeBaseCommit"
|
||||
);
|
||||
// Not triggered by a pull request
|
||||
t.falsy(pushPayload.base_ref);
|
||||
t.falsy(pushPayload.base_sha);
|
||||
|
||||
process.env["GITHUB_EVENT_NAME"] = "pull_request";
|
||||
process.env["GITHUB_SHA"] = "commit";
|
||||
@@ -72,62 +53,40 @@ test("validate correct payload used per version", async (t) => {
|
||||
process.env[
|
||||
"GITHUB_EVENT_PATH"
|
||||
] = `${__dirname}/../src/testdata/pull_request.json`;
|
||||
for (const version of newVersions) {
|
||||
const payload: any = uploadLib.buildPayload(
|
||||
"commit",
|
||||
"refs/pull/123/merge",
|
||||
"key",
|
||||
undefined,
|
||||
"",
|
||||
undefined,
|
||||
"/opt/src",
|
||||
undefined,
|
||||
["CodeQL", "eslint"],
|
||||
version,
|
||||
"mergeBaseCommit"
|
||||
);
|
||||
// Uploads for a merge commit use the merge base
|
||||
t.deepEqual(payload.base_ref, "refs/heads/master");
|
||||
t.deepEqual(payload.base_sha, "mergeBaseCommit");
|
||||
}
|
||||
const prMergePayload: any = uploadLib.buildPayload(
|
||||
"commit",
|
||||
"refs/pull/123/merge",
|
||||
"key",
|
||||
undefined,
|
||||
"",
|
||||
undefined,
|
||||
"/opt/src",
|
||||
undefined,
|
||||
["CodeQL", "eslint"],
|
||||
"mergeBaseCommit"
|
||||
);
|
||||
// Uploads for a merge commit use the merge base
|
||||
t.deepEqual(prMergePayload.base_ref, "refs/heads/master");
|
||||
t.deepEqual(prMergePayload.base_sha, "mergeBaseCommit");
|
||||
|
||||
for (const version of newVersions) {
|
||||
const payload: any = uploadLib.buildPayload(
|
||||
"headCommit",
|
||||
"refs/pull/123/head",
|
||||
"key",
|
||||
undefined,
|
||||
"",
|
||||
undefined,
|
||||
"/opt/src",
|
||||
undefined,
|
||||
["CodeQL", "eslint"],
|
||||
version,
|
||||
"mergeBaseCommit"
|
||||
);
|
||||
// Uploads for the head use the PR base
|
||||
t.deepEqual(payload.base_ref, "refs/heads/master");
|
||||
t.deepEqual(payload.base_sha, "f95f852bd8fca8fcc58a9a2d6c842781e32a215e");
|
||||
}
|
||||
|
||||
for (const version of oldVersions) {
|
||||
const payload: any = uploadLib.buildPayload(
|
||||
"commit",
|
||||
"refs/pull/123/merge",
|
||||
"key",
|
||||
undefined,
|
||||
"",
|
||||
undefined,
|
||||
"/opt/src",
|
||||
undefined,
|
||||
["CodeQL", "eslint"],
|
||||
version,
|
||||
"mergeBaseCommit"
|
||||
);
|
||||
// These older versions won't expect these values
|
||||
t.falsy(payload.base_ref);
|
||||
t.falsy(payload.base_sha);
|
||||
}
|
||||
const prHeadPayload: any = uploadLib.buildPayload(
|
||||
"headCommit",
|
||||
"refs/pull/123/head",
|
||||
"key",
|
||||
undefined,
|
||||
"",
|
||||
undefined,
|
||||
"/opt/src",
|
||||
undefined,
|
||||
["CodeQL", "eslint"],
|
||||
"mergeBaseCommit"
|
||||
);
|
||||
// Uploads for the head use the PR base
|
||||
t.deepEqual(prHeadPayload.base_ref, "refs/heads/master");
|
||||
t.deepEqual(
|
||||
prHeadPayload.base_sha,
|
||||
"f95f852bd8fca8fcc58a9a2d6c842781e32a215e"
|
||||
);
|
||||
});
|
||||
|
||||
test("finding SARIF files", async (t) => {
|
||||
|
||||
@@ -7,7 +7,6 @@ import * as core from "@actions/core";
|
||||
import { OctokitResponse } from "@octokit/types";
|
||||
import fileUrl from "file-url";
|
||||
import * as jsonschema from "jsonschema";
|
||||
import * as semver from "semver";
|
||||
|
||||
import * as actionsUtil from "./actions-util";
|
||||
import * as api from "./api-client";
|
||||
@@ -161,7 +160,6 @@ export function findSarifFilesInDir(sarifPath: string): string[] {
|
||||
// Returns true iff the upload occurred and succeeded
|
||||
export async function uploadFromActions(
|
||||
sarifPath: string,
|
||||
gitHubVersion: util.GitHubVersion,
|
||||
logger: Logger
|
||||
): Promise<UploadResult> {
|
||||
return await uploadFiles(
|
||||
@@ -177,7 +175,6 @@ export async function uploadFromActions(
|
||||
actionsUtil.getWorkflowRunID(),
|
||||
actionsUtil.getRequiredInput("checkout_path"),
|
||||
actionsUtil.getRequiredInput("matrix"),
|
||||
gitHubVersion,
|
||||
logger
|
||||
);
|
||||
}
|
||||
@@ -263,7 +260,6 @@ export function buildPayload(
|
||||
checkoutURI: string,
|
||||
environment: string | undefined,
|
||||
toolNames: string[],
|
||||
gitHubVersion: util.GitHubVersion,
|
||||
mergeBaseCommitOid: string | undefined
|
||||
) {
|
||||
const payloadObj = {
|
||||
@@ -281,33 +277,27 @@ export function buildPayload(
|
||||
base_sha: undefined as undefined | string,
|
||||
};
|
||||
|
||||
// This behaviour can be made the default when support for GHES 3.0 is discontinued.
|
||||
if (
|
||||
gitHubVersion.type !== util.GitHubVariant.GHES ||
|
||||
semver.satisfies(gitHubVersion.version, `>=3.1`)
|
||||
) {
|
||||
if (actionsUtil.workflowEventName() === "pull_request") {
|
||||
if (
|
||||
commitOid === util.getRequiredEnvParam("GITHUB_SHA") &&
|
||||
mergeBaseCommitOid
|
||||
) {
|
||||
// We're uploading results for the merge commit
|
||||
// and were able to determine the merge base.
|
||||
// So we use that as the most accurate base.
|
||||
payloadObj.base_ref = `refs/heads/${util.getRequiredEnvParam(
|
||||
"GITHUB_BASE_REF"
|
||||
)}`;
|
||||
payloadObj.base_sha = mergeBaseCommitOid;
|
||||
} else if (process.env.GITHUB_EVENT_PATH) {
|
||||
// Either we're not uploading results for the merge commit
|
||||
// or we could not determine the merge base.
|
||||
// Using the PR base is the only option here
|
||||
const githubEvent = JSON.parse(
|
||||
fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8")
|
||||
);
|
||||
payloadObj.base_ref = `refs/heads/${githubEvent.pull_request.base.ref}`;
|
||||
payloadObj.base_sha = githubEvent.pull_request.base.sha;
|
||||
}
|
||||
if (actionsUtil.workflowEventName() === "pull_request") {
|
||||
if (
|
||||
commitOid === util.getRequiredEnvParam("GITHUB_SHA") &&
|
||||
mergeBaseCommitOid
|
||||
) {
|
||||
// We're uploading results for the merge commit
|
||||
// and were able to determine the merge base.
|
||||
// So we use that as the most accurate base.
|
||||
payloadObj.base_ref = `refs/heads/${util.getRequiredEnvParam(
|
||||
"GITHUB_BASE_REF"
|
||||
)}`;
|
||||
payloadObj.base_sha = mergeBaseCommitOid;
|
||||
} else if (process.env.GITHUB_EVENT_PATH) {
|
||||
// Either we're not uploading results for the merge commit
|
||||
// or we could not determine the merge base.
|
||||
// Using the PR base is the only option here
|
||||
const githubEvent = JSON.parse(
|
||||
fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8")
|
||||
);
|
||||
payloadObj.base_ref = `refs/heads/${githubEvent.pull_request.base.ref}`;
|
||||
payloadObj.base_sha = githubEvent.pull_request.base.sha;
|
||||
}
|
||||
}
|
||||
return payloadObj;
|
||||
@@ -326,7 +316,6 @@ async function uploadFiles(
|
||||
workflowRunID: number | undefined,
|
||||
sourceRoot: string,
|
||||
environment: string | undefined,
|
||||
gitHubVersion: util.GitHubVersion,
|
||||
logger: Logger
|
||||
): Promise<UploadResult> {
|
||||
logger.startGroup("Uploading results");
|
||||
@@ -367,7 +356,6 @@ async function uploadFiles(
|
||||
checkoutURI,
|
||||
environment,
|
||||
toolNames,
|
||||
gitHubVersion,
|
||||
await actionsUtil.determineMergeBaseCommitOid()
|
||||
);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import * as core from "@actions/core";
|
||||
|
||||
import * as actionsUtil from "./actions-util";
|
||||
import { getGitHubVersion } from "./api-client";
|
||||
import { getActionsLogger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
@@ -52,11 +51,8 @@ async function run() {
|
||||
}
|
||||
|
||||
try {
|
||||
const gitHubVersion = await getGitHubVersion();
|
||||
|
||||
const uploadResult = await upload_lib.uploadFromActions(
|
||||
actionsUtil.getRequiredInput("sarif_file"),
|
||||
gitHubVersion,
|
||||
getActionsLogger()
|
||||
);
|
||||
core.setOutput("sarif-id", uploadResult.sarifID);
|
||||
|
||||
Reference in New Issue
Block a user