Add option tools: linked for init action.
Also ensure that option latest remains compatible, and add tests for the two options.
This commit is contained in:
parent
bf2faab135
commit
cbe408dfc9
9 changed files with 101 additions and 12 deletions
|
|
@ -7,8 +7,10 @@ import * as actionsUtil from "./actions-util";
|
|||
import { getRunnerLogger } from "./logging";
|
||||
import * as setupCodeql from "./setup-codeql";
|
||||
import {
|
||||
LINKED_CLI_VERSION,
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
getRecordingLogger,
|
||||
mockBundleDownloadApi,
|
||||
setupActionsVars,
|
||||
setupTests,
|
||||
|
|
@ -93,3 +95,41 @@ test("getCodeQLSource sets CLI version for a semver tagged bundle", async (t) =>
|
|||
t.is(source["cliVersion"], "1.2.3");
|
||||
});
|
||||
});
|
||||
|
||||
test("getCodeQLSource correctly returns bundled CLI version when tools == linked", async (t) => {
|
||||
const loggedMessages = [];
|
||||
const logger = getRecordingLogger(loggedMessages);
|
||||
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
const source = await setupCodeql.getCodeQLSource(
|
||||
"linked",
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
GitHubVariant.DOTCOM,
|
||||
logger,
|
||||
);
|
||||
|
||||
t.is(source.toolsVersion, LINKED_CLI_VERSION.cliVersion);
|
||||
t.is(source.sourceType, "download");
|
||||
});
|
||||
});
|
||||
|
||||
test("getCodeQLSource correctly returns bundled CLI version when tools == latest", async (t) => {
|
||||
const loggedMessages = [];
|
||||
const logger = getRecordingLogger(loggedMessages);
|
||||
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
const source = await setupCodeql.getCodeQLSource(
|
||||
"latest",
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
SAMPLE_DOTCOM_API_DETAILS,
|
||||
GitHubVariant.DOTCOM,
|
||||
logger,
|
||||
);
|
||||
|
||||
t.is(source.toolsVersion, LINKED_CLI_VERSION.cliVersion);
|
||||
t.is(source.sourceType, "download");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ export enum ToolsSource {
|
|||
|
||||
export const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||
|
||||
const CODEQL_BUNDLE_VERSION_ALIAS: string[] = ["linked", "latest"];
|
||||
|
||||
function getCodeQLBundleName(): string {
|
||||
let platform: string;
|
||||
if (process.platform === "win32") {
|
||||
|
|
@ -281,7 +283,11 @@ export async function getCodeQLSource(
|
|||
variant: util.GitHubVariant,
|
||||
logger: Logger,
|
||||
): Promise<CodeQLToolsSource> {
|
||||
if (toolsInput && toolsInput !== "latest" && !toolsInput.startsWith("http")) {
|
||||
if (
|
||||
toolsInput &&
|
||||
!CODEQL_BUNDLE_VERSION_ALIAS.includes(toolsInput) &&
|
||||
!toolsInput.startsWith("http")
|
||||
) {
|
||||
return {
|
||||
codeqlTarPath: toolsInput,
|
||||
sourceType: "local",
|
||||
|
|
@ -292,15 +298,20 @@ export async function getCodeQLSource(
|
|||
/**
|
||||
* Whether the tools shipped with the Action, i.e. those in `defaults.json`, have been forced.
|
||||
*
|
||||
* We use the special value of 'latest' to prioritize the version in `defaults.json` over the
|
||||
* We use the special value of 'linked' to prioritize the version in `defaults.json` over the
|
||||
* version specified by the feature flags on Dotcom and over any pinned cached version on
|
||||
* Enterprise Server.
|
||||
*
|
||||
* Previously we have been using 'latest' to force the shipped tools, but this was not clear
|
||||
* enough for the users, so it has been changed to `linked`. We're keeping around `latest` for
|
||||
* backwards compatibility.
|
||||
*/
|
||||
const forceShippedTools = toolsInput === "latest";
|
||||
const forceShippedTools =
|
||||
toolsInput && CODEQL_BUNDLE_VERSION_ALIAS.includes(toolsInput);
|
||||
if (forceShippedTools) {
|
||||
logger.info(
|
||||
"Overriding the version of the CodeQL tools by the version shipped with the Action since " +
|
||||
`"tools: latest" was requested.`,
|
||||
`"tools: linked" or "tools: latest" was requested.`,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import * as apiClient from "./api-client";
|
|||
import { GitHubApiDetails } from "./api-client";
|
||||
import * as codeql from "./codeql";
|
||||
import { Config } from "./config-utils";
|
||||
import * as defaults from "./defaults.json";
|
||||
import {
|
||||
CodeQLDefaultVersionInfo,
|
||||
Feature,
|
||||
|
|
@ -35,6 +36,11 @@ export const SAMPLE_DEFAULT_CLI_VERSION: CodeQLDefaultVersionInfo = {
|
|||
tagName: "codeql-bundle-v2.20.0",
|
||||
};
|
||||
|
||||
export const LINKED_CLI_VERSION = {
|
||||
cliVersion: defaults.cliVersion,
|
||||
tagName: defaults.bundleVersion,
|
||||
};
|
||||
|
||||
type TestContext = {
|
||||
stdoutWrite: any;
|
||||
stderrWrite: any;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue