Skip to content

Commit

Permalink
Only log the version warning once on Actions even if the Action is in…
Browse files Browse the repository at this point in the history
…voked multiple times.
  • Loading branch information
Chris Gavin committed Nov 2, 2020
1 parent 865b4bd commit 1a4385d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/api-client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/api-client.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from "path";

import { exportVariable } from "@actions/core";
import * as githubUtils from "@actions/github/lib/utils";
import * as retry from "@octokit/plugin-retry";
import { OctokitResponse } from "@octokit/types";
Expand All @@ -17,6 +18,8 @@ export enum 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;

export const getApiClient = function (
Expand All @@ -33,7 +36,8 @@ export const getApiClient = function (
octokit.hook.after("request", (response: OctokitResponse<any>, _) => {
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
Expand Down Expand Up @@ -63,6 +67,9 @@ export const getApiClient = function (
);
}
hasBeenWarnedAboutVersion = true;
if (mode === "actions") {
exportVariable(CODEQL_ACTION_WARNED_ABOUT_VERSION_ENV_VAR, true);
}
}
});
});
Expand Down

0 comments on commit 1a4385d

Please sign in to comment.