Only log the version warning once on Actions even if the Action is invoked multiple times.

This commit is contained in:
Chris Gavin 2020-11-02 09:01:36 +00:00
parent 865b4bd832
commit 1a4385d516
No known key found for this signature in database
GPG key ID: 07F950B80C27E4DA
3 changed files with 16 additions and 3 deletions

8
lib/api-client.js generated
View file

@ -11,6 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = __importStar(require("path"));
const core_1 = require("@actions/core");
const githubUtils = __importStar(require("@actions/github/lib/utils"));
const retry = __importStar(require("@octokit/plugin-retry"));
const console_log_level_1 = __importDefault(require("console-log-level"));
@ -25,6 +26,7 @@ var DisallowedAPIVersionReason;
DisallowedAPIVersionReason[DisallowedAPIVersionReason["ACTION_TOO_NEW"] = 1] = "ACTION_TOO_NEW";
})(DisallowedAPIVersionReason = exports.DisallowedAPIVersionReason || (exports.DisallowedAPIVersionReason = {}));
const GITHUB_ENTERPRISE_VERSION_HEADER = "x-github-enterprise-version";
const CODEQL_ACTION_WARNED_ABOUT_VERSION_ENV_VAR = "CODEQL_ACTION_WARNED_ABOUT_VERSION";
let hasBeenWarnedAboutVersion = false;
exports.getApiClient = function (githubAuth, githubUrl, mode, logger, allowLocalRun = false) {
if (util_1.isLocalRun() && !allowLocalRun) {
@ -33,7 +35,8 @@ exports.getApiClient = function (githubAuth, githubUrl, mode, logger, allowLocal
const customOctokit = githubUtils.GitHub.plugin(retry.retry, (octokit, _) => {
octokit.hook.after("request", (response, _) => {
if (!hasBeenWarnedAboutVersion &&
response.headers[GITHUB_ENTERPRISE_VERSION_HEADER] !== undefined) {
response.headers[GITHUB_ENTERPRISE_VERSION_HEADER] !== undefined &&
process.env[CODEQL_ACTION_WARNED_ABOUT_VERSION_ENV_VAR] !== undefined) {
const installedVersion = response.headers[GITHUB_ENTERPRISE_VERSION_HEADER];
const disallowedAPIVersionReason = apiVersionInRange(installedVersion, apiCompatibility.minimumVersion, apiCompatibility.maximumVersion);
const toolName = mode === "actions" ? "Action" : "Runner";
@ -46,6 +49,9 @@ exports.getApiClient = function (githubAuth, githubUrl, mode, logger, allowLocal
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;
if (mode === "actions") {
core_1.exportVariable(CODEQL_ACTION_WARNED_ABOUT_VERSION_ENV_VAR, true);
}
}
});
});