Remove fallback logic for GHES 2.22 when determining Action repository

This commit is contained in:
Henry Mercer 2022-11-23 18:19:25 +00:00
parent 39fe7aa8a1
commit bc341c5dd1
6 changed files with 14 additions and 23 deletions

10
lib/codeql.js generated
View file

@ -120,20 +120,14 @@ function getCodeQLBundleName() {
return `codeql-bundle-${platform}.tar.gz`; return `codeql-bundle-${platform}.tar.gz`;
} }
function getCodeQLActionRepository(logger) { function getCodeQLActionRepository(logger) {
if (process.env["GITHUB_ACTION_REPOSITORY"] !== undefined) {
return process.env["GITHUB_ACTION_REPOSITORY"];
}
// The Actions Runner used with GitHub Enterprise Server 2.22 did not set the GITHUB_ACTION_REPOSITORY variable.
// This fallback logic can be removed after the end-of-support for 2.22 on 2021-09-23.
if ((0, actions_util_1.isRunningLocalAction)()) { if ((0, actions_util_1.isRunningLocalAction)()) {
// This handles the case where the Action does not come from an Action repository, // This handles the case where the Action does not come from an Action repository,
// e.g. our integration tests which use the Action code from the current checkout. // e.g. our integration tests which use the Action code from the current checkout.
// In these cases, the GITHUB_ACTION_REPOSITORY environment variable is not set.
logger.info("The CodeQL Action is checked out locally. Using the default CodeQL Action repository."); logger.info("The CodeQL Action is checked out locally. Using the default CodeQL Action repository.");
return exports.CODEQL_DEFAULT_ACTION_REPOSITORY; return exports.CODEQL_DEFAULT_ACTION_REPOSITORY;
} }
logger.info("GITHUB_ACTION_REPOSITORY environment variable was not set. Falling back to legacy method of finding the GitHub Action."); return util.getRequiredEnvParam("GITHUB_ACTION_REPOSITORY");
const relativeScriptPathParts = (0, actions_util_1.getRelativeScriptPath)().split(path.sep);
return `${relativeScriptPathParts[0]}/${relativeScriptPathParts[1]}`;
} }
exports.getCodeQLActionRepository = getCodeQLActionRepository; exports.getCodeQLActionRepository = getCodeQLActionRepository;
async function getCodeQLBundleDownloadURL(apiDetails, variant, logger) { async function getCodeQLBundleDownloadURL(apiDetails, variant, logger) {

File diff suppressed because one or more lines are too long

3
lib/codeql.test.js generated
View file

@ -32,6 +32,7 @@ const del_1 = __importDefault(require("del"));
const yaml = __importStar(require("js-yaml")); const yaml = __importStar(require("js-yaml"));
const nock_1 = __importDefault(require("nock")); const nock_1 = __importDefault(require("nock"));
const sinon = __importStar(require("sinon")); const sinon = __importStar(require("sinon"));
const actionsUtil = __importStar(require("./actions-util"));
const codeql = __importStar(require("./codeql")); const codeql = __importStar(require("./codeql"));
const defaults = __importStar(require("./defaults.json")); const defaults = __importStar(require("./defaults.json"));
const feature_flags_1 = require("./feature-flags"); const feature_flags_1 = require("./feature-flags");
@ -297,6 +298,8 @@ for (const [isFeatureEnabled, toolsInput, shouldToolcacheBeBypassed,] of TOOLCAC
process.env["RUNNER_TEMP"] = path.dirname(__dirname); process.env["RUNNER_TEMP"] = path.dirname(__dirname);
const repoLocalRunner = codeql.getCodeQLActionRepository(logger); const repoLocalRunner = codeql.getCodeQLActionRepository(logger);
t.deepEqual(repoLocalRunner, "github/codeql-action"); t.deepEqual(repoLocalRunner, "github/codeql-action");
// isRunningLocalAction() === false
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
process.env["GITHUB_ACTION_REPOSITORY"] = "xxx/yyy"; process.env["GITHUB_ACTION_REPOSITORY"] = "xxx/yyy";
const repoEnv = codeql.getCodeQLActionRepository(logger); const repoEnv = codeql.getCodeQLActionRepository(logger);
t.deepEqual(repoEnv, "xxx/yyy"); t.deepEqual(repoEnv, "xxx/yyy");

File diff suppressed because one or more lines are too long

View file

@ -9,6 +9,7 @@ import * as yaml from "js-yaml";
import nock from "nock"; import nock from "nock";
import * as sinon from "sinon"; import * as sinon from "sinon";
import * as actionsUtil from "./actions-util";
import { GitHubApiDetails } from "./api-client"; import { GitHubApiDetails } from "./api-client";
import * as codeql from "./codeql"; import * as codeql from "./codeql";
import { AugmentationProperties, Config } from "./config-utils"; import { AugmentationProperties, Config } from "./config-utils";
@ -432,6 +433,8 @@ test("getCodeQLActionRepository", (t) => {
const repoLocalRunner = codeql.getCodeQLActionRepository(logger); const repoLocalRunner = codeql.getCodeQLActionRepository(logger);
t.deepEqual(repoLocalRunner, "github/codeql-action"); t.deepEqual(repoLocalRunner, "github/codeql-action");
// isRunningLocalAction() === false
sinon.stub(actionsUtil, "isRunningLocalAction").returns(false);
process.env["GITHUB_ACTION_REPOSITORY"] = "xxx/yyy"; process.env["GITHUB_ACTION_REPOSITORY"] = "xxx/yyy";
const repoEnv = codeql.getCodeQLActionRepository(logger); const repoEnv = codeql.getCodeQLActionRepository(logger);
t.deepEqual(repoEnv, "xxx/yyy"); t.deepEqual(repoEnv, "xxx/yyy");

View file

@ -10,7 +10,7 @@ import { default as queryString } from "query-string";
import * as semver from "semver"; import * as semver from "semver";
import { v4 as uuidV4 } from "uuid"; import { v4 as uuidV4 } from "uuid";
import { getRelativeScriptPath, isRunningLocalAction } from "./actions-util"; import { isRunningLocalAction } from "./actions-util";
import * as api from "./api-client"; import * as api from "./api-client";
import { Config } from "./config-utils"; import { Config } from "./config-utils";
import * as defaults from "./defaults.json"; // Referenced from codeql-action-sync-tool! import * as defaults from "./defaults.json"; // Referenced from codeql-action-sync-tool!
@ -296,26 +296,17 @@ function getCodeQLBundleName(): string {
} }
export function getCodeQLActionRepository(logger: Logger): string { export function getCodeQLActionRepository(logger: Logger): string {
if (process.env["GITHUB_ACTION_REPOSITORY"] !== undefined) {
return process.env["GITHUB_ACTION_REPOSITORY"];
}
// The Actions Runner used with GitHub Enterprise Server 2.22 did not set the GITHUB_ACTION_REPOSITORY variable.
// This fallback logic can be removed after the end-of-support for 2.22 on 2021-09-23.
if (isRunningLocalAction()) { if (isRunningLocalAction()) {
// This handles the case where the Action does not come from an Action repository, // This handles the case where the Action does not come from an Action repository,
// e.g. our integration tests which use the Action code from the current checkout. // e.g. our integration tests which use the Action code from the current checkout.
// In these cases, the GITHUB_ACTION_REPOSITORY environment variable is not set.
logger.info( logger.info(
"The CodeQL Action is checked out locally. Using the default CodeQL Action repository." "The CodeQL Action is checked out locally. Using the default CodeQL Action repository."
); );
return CODEQL_DEFAULT_ACTION_REPOSITORY; return CODEQL_DEFAULT_ACTION_REPOSITORY;
} }
logger.info(
"GITHUB_ACTION_REPOSITORY environment variable was not set. Falling back to legacy method of finding the GitHub Action." return util.getRequiredEnvParam("GITHUB_ACTION_REPOSITORY");
);
const relativeScriptPathParts = getRelativeScriptPath().split(path.sep);
return `${relativeScriptPathParts[0]}/${relativeScriptPathParts[1]}`;
} }
async function getCodeQLBundleDownloadURL( async function getCodeQLBundleDownloadURL(