Log a warning if the API version is not supported.
This commit is contained in:
parent
46110c361b
commit
1220ae5bfd
34 changed files with 369 additions and 61 deletions
|
|
@ -2,21 +2,77 @@ import * as path from "path";
|
|||
|
||||
import * as githubUtils from "@actions/github/lib/utils";
|
||||
import * as retry from "@octokit/plugin-retry";
|
||||
import { OctokitResponse } from "@octokit/types";
|
||||
import consoleLogLevel from "console-log-level";
|
||||
import * as semver from "semver";
|
||||
|
||||
import { getRequiredEnvParam, getRequiredInput } from "./actions-util";
|
||||
import { isLocalRun } from "./util";
|
||||
import * as apiCompatibility from "./api-compatibility.json";
|
||||
import * as logging from "./logging";
|
||||
import { isLocalRun, Mode } from "./util";
|
||||
|
||||
export enum DisallowedAPIVersionReason {
|
||||
ACTION_TOO_OLD,
|
||||
ACTION_TOO_NEW,
|
||||
}
|
||||
|
||||
const GITHUB_ENTERPRISE_VERSION_HEADER = "x-github-enterprise-version";
|
||||
let hasBeenWarnedAboutVersion = false;
|
||||
|
||||
export const getApiClient = function (
|
||||
githubAuth: string,
|
||||
githubUrl: string,
|
||||
mode: Mode,
|
||||
allowLocalRun = false
|
||||
) {
|
||||
if (isLocalRun() && !allowLocalRun) {
|
||||
throw new Error("Invalid API call in local run");
|
||||
}
|
||||
const retryingOctokit = githubUtils.GitHub.plugin(retry.retry);
|
||||
return new retryingOctokit(
|
||||
const customOctokit = githubUtils.GitHub.plugin(retry.retry, (octokit, _) => {
|
||||
octokit.hook.after("request", (response: OctokitResponse<any>, _) => {
|
||||
if (
|
||||
!hasBeenWarnedAboutVersion &&
|
||||
Object.prototype.hasOwnProperty.call(
|
||||
response.headers,
|
||||
GITHUB_ENTERPRISE_VERSION_HEADER
|
||||
)
|
||||
) {
|
||||
const installedVersion = response.headers[
|
||||
GITHUB_ENTERPRISE_VERSION_HEADER
|
||||
] as string;
|
||||
const disallowedAPIVersionReason = apiVersionInRange(
|
||||
installedVersion,
|
||||
apiCompatibility.minimumVersion,
|
||||
apiCompatibility.maximumVersion
|
||||
);
|
||||
|
||||
const logger =
|
||||
mode === "actions"
|
||||
? logging.getActionsLogger()
|
||||
: logging.getRunnerLogger(false);
|
||||
const toolName = mode === "actions" ? "Action" : "Runner";
|
||||
|
||||
if (
|
||||
disallowedAPIVersionReason ===
|
||||
DisallowedAPIVersionReason.ACTION_TOO_OLD
|
||||
) {
|
||||
logger.warning(
|
||||
`The CodeQL ${toolName} version you are using is too old to be compatible with GitHub Enterprise ${installedVersion}. If you experience issues, please upgrade to a more recent version of the CodeQL ${toolName}.`
|
||||
);
|
||||
}
|
||||
if (
|
||||
disallowedAPIVersionReason ===
|
||||
DisallowedAPIVersionReason.ACTION_TOO_NEW
|
||||
) {
|
||||
logger.warning(
|
||||
`GitHub Enterprise ${installedVersion} is too old to be compatible with this version of the CodeQL ${toolName}. If you experience issues, please upgrade to a more recent version of GitHub Enterprise or use an older version of the CodeQL ${toolName}.`
|
||||
);
|
||||
}
|
||||
hasBeenWarnedAboutVersion = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
return new customOctokit(
|
||||
githubUtils.getOctokitOptions(githubAuth, {
|
||||
baseUrl: getApiUrl(githubUrl),
|
||||
userAgent: "CodeQL Action",
|
||||
|
|
@ -46,6 +102,21 @@ export function getActionsApiClient(allowLocalRun = false) {
|
|||
return getApiClient(
|
||||
getRequiredInput("token"),
|
||||
getRequiredEnvParam("GITHUB_SERVER_URL"),
|
||||
"actions",
|
||||
allowLocalRun
|
||||
);
|
||||
}
|
||||
|
||||
export function apiVersionInRange(
|
||||
version: string,
|
||||
minimumVersion: string,
|
||||
maximumVersion: string
|
||||
): DisallowedAPIVersionReason | undefined {
|
||||
if (!semver.satisfies(version, `>=${minimumVersion}`)) {
|
||||
return DisallowedAPIVersionReason.ACTION_TOO_NEW;
|
||||
}
|
||||
if (!semver.satisfies(version, `<=${maximumVersion}`)) {
|
||||
return DisallowedAPIVersionReason.ACTION_TOO_OLD;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue