mirror of
https://github.com/github/codeql-action.git
synced 2025-12-24 08:10:06 +08:00
Add test for using default version with no requested URL on Dotcom
This commit is contained in:
45
lib/codeql.test.js
generated
45
lib/codeql.test.js
generated
@@ -34,6 +34,7 @@ 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 actionsUtil = __importStar(require("./actions-util"));
|
||||||
|
const api = __importStar(require("./api-client"));
|
||||||
const codeql = __importStar(require("./codeql"));
|
const codeql = __importStar(require("./codeql"));
|
||||||
const defaults = __importStar(require("./defaults.json")); // Referenced from codeql-action-sync-tool!
|
const defaults = __importStar(require("./defaults.json")); // Referenced from codeql-action-sync-tool!
|
||||||
const feature_flags_1 = require("./feature-flags");
|
const feature_flags_1 = require("./feature-flags");
|
||||||
@@ -107,9 +108,11 @@ async function mockDownloadApi({ apiDetails = sampleApiDetails, isPinned, tagNam
|
|||||||
.replyWithFile(200, path_1.default.join(__dirname, `/../src/testdata/codeql-bundle${isPinned ? "-pinned" : ""}.tar.gz`));
|
.replyWithFile(200, path_1.default.join(__dirname, `/../src/testdata/codeql-bundle${isPinned ? "-pinned" : ""}.tar.gz`));
|
||||||
return `${baseUrl}${relativeUrl}`;
|
return `${baseUrl}${relativeUrl}`;
|
||||||
}
|
}
|
||||||
async function installIntoToolcache({ apiDetails = sampleApiDetails, isPinned, tagName, tmpDir, }) {
|
async function installIntoToolcache({ apiDetails = sampleApiDetails, cliVersion, isPinned, tagName, tmpDir, }) {
|
||||||
const url = await mockDownloadApi({ apiDetails, isPinned, tagName });
|
const url = await mockDownloadApi({ apiDetails, isPinned, tagName });
|
||||||
await codeql.setupCodeQL(url, apiDetails, tmpDir, util.GitHubVariant.DOTCOM, false, SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), false);
|
await codeql.setupCodeQL(cliVersion !== undefined ? undefined : url, apiDetails, tmpDir, util.GitHubVariant.GHES, false, cliVersion !== undefined
|
||||||
|
? { cliVersion, tagName, variant: util.GitHubVariant.GHES }
|
||||||
|
: SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), false);
|
||||||
}
|
}
|
||||||
(0, ava_1.default)("downloads and caches explicitly requested bundles that aren't in the toolcache", async (t) => {
|
(0, ava_1.default)("downloads and caches explicitly requested bundles that aren't in the toolcache", async (t) => {
|
||||||
await util.withTmpDir(async (tmpDir) => {
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
@@ -144,6 +147,44 @@ async function installIntoToolcache({ apiDetails = sampleApiDetails, isPinned, t
|
|||||||
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
for (const isCached of [true, false]) {
|
||||||
|
(0, ava_1.default)(`uses default version on Dotcom when default version bundle is ${isCached ? "" : "not "}cached`, async (t) => {
|
||||||
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
|
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||||
|
const tagName = `codeql-bundle-20230101`;
|
||||||
|
if (isCached) {
|
||||||
|
await installIntoToolcache({
|
||||||
|
cliVersion: SAMPLE_DEFAULT_CLI_VERSION.cliVersion,
|
||||||
|
tagName,
|
||||||
|
isPinned: true,
|
||||||
|
tmpDir,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await mockDownloadApi({
|
||||||
|
tagName,
|
||||||
|
});
|
||||||
|
sinon.stub(api, "getApiClient").value(() => ({
|
||||||
|
repos: {
|
||||||
|
listReleases: sinon.stub().resolves(undefined),
|
||||||
|
},
|
||||||
|
paginate: sinon.stub().resolves([
|
||||||
|
{
|
||||||
|
assets: [
|
||||||
|
{
|
||||||
|
name: "cli-version-2.0.0.txt",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tag_name: tagName,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
const result = await codeql.setupCodeQL(undefined, sampleApiDetails, tmpDir, util.GitHubVariant.DOTCOM, false, SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), false);
|
||||||
|
t.is(result.toolsVersion, SAMPLE_DEFAULT_CLI_VERSION.cliVersion);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
|
for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
|
||||||
(0, ava_1.default)(`uses a cached bundle when no tools input is given on ${util.GitHubVariant[variant]}`, async (t) => {
|
(0, ava_1.default)(`uses a cached bundle when no tools input is given on ${util.GitHubVariant[variant]}`, async (t) => {
|
||||||
await util.withTmpDir(async (tmpDir) => {
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -11,6 +11,7 @@ import nock from "nock";
|
|||||||
import * as sinon from "sinon";
|
import * as sinon from "sinon";
|
||||||
|
|
||||||
import * as actionsUtil from "./actions-util";
|
import * as actionsUtil from "./actions-util";
|
||||||
|
import * as api from "./api-client";
|
||||||
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";
|
||||||
@@ -118,23 +119,27 @@ async function mockDownloadApi({
|
|||||||
|
|
||||||
async function installIntoToolcache({
|
async function installIntoToolcache({
|
||||||
apiDetails = sampleApiDetails,
|
apiDetails = sampleApiDetails,
|
||||||
|
cliVersion,
|
||||||
isPinned,
|
isPinned,
|
||||||
tagName,
|
tagName,
|
||||||
tmpDir,
|
tmpDir,
|
||||||
}: {
|
}: {
|
||||||
apiDetails?: GitHubApiDetails;
|
apiDetails?: GitHubApiDetails;
|
||||||
|
cliVersion?: string;
|
||||||
isPinned: boolean;
|
isPinned: boolean;
|
||||||
tagName: string;
|
tagName: string;
|
||||||
tmpDir: string;
|
tmpDir: string;
|
||||||
}) {
|
}) {
|
||||||
const url = await mockDownloadApi({ apiDetails, isPinned, tagName });
|
const url = await mockDownloadApi({ apiDetails, isPinned, tagName });
|
||||||
await codeql.setupCodeQL(
|
await codeql.setupCodeQL(
|
||||||
url,
|
cliVersion !== undefined ? undefined : url,
|
||||||
apiDetails,
|
apiDetails,
|
||||||
tmpDir,
|
tmpDir,
|
||||||
util.GitHubVariant.DOTCOM,
|
util.GitHubVariant.GHES,
|
||||||
false,
|
false,
|
||||||
SAMPLE_DEFAULT_CLI_VERSION,
|
cliVersion !== undefined
|
||||||
|
? { cliVersion, tagName, variant: util.GitHubVariant.GHES }
|
||||||
|
: SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@@ -199,6 +204,58 @@ test("downloads an explicitly requested bundle even if a different version is ca
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (const isCached of [true, false]) {
|
||||||
|
test(`uses default version on Dotcom when default version bundle is ${
|
||||||
|
isCached ? "" : "not "
|
||||||
|
}cached`, async (t) => {
|
||||||
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
|
setupActionsVars(tmpDir, tmpDir);
|
||||||
|
|
||||||
|
const tagName = `codeql-bundle-20230101`;
|
||||||
|
|
||||||
|
if (isCached) {
|
||||||
|
await installIntoToolcache({
|
||||||
|
cliVersion: SAMPLE_DEFAULT_CLI_VERSION.cliVersion,
|
||||||
|
tagName,
|
||||||
|
isPinned: true,
|
||||||
|
tmpDir,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await mockDownloadApi({
|
||||||
|
tagName,
|
||||||
|
});
|
||||||
|
sinon.stub(api, "getApiClient").value(() => ({
|
||||||
|
repos: {
|
||||||
|
listReleases: sinon.stub().resolves(undefined),
|
||||||
|
},
|
||||||
|
paginate: sinon.stub().resolves([
|
||||||
|
{
|
||||||
|
assets: [
|
||||||
|
{
|
||||||
|
name: "cli-version-2.0.0.txt",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tag_name: tagName,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await codeql.setupCodeQL(
|
||||||
|
undefined,
|
||||||
|
sampleApiDetails,
|
||||||
|
tmpDir,
|
||||||
|
util.GitHubVariant.DOTCOM,
|
||||||
|
false,
|
||||||
|
SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
|
getRunnerLogger(true),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
t.is(result.toolsVersion, SAMPLE_DEFAULT_CLI_VERSION.cliVersion);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
|
for (const variant of [util.GitHubVariant.GHAE, util.GitHubVariant.GHES]) {
|
||||||
test(`uses a cached bundle when no tools input is given on ${util.GitHubVariant[variant]}`, async (t) => {
|
test(`uses a cached bundle when no tools input is given on ${util.GitHubVariant[variant]}`, async (t) => {
|
||||||
await util.withTmpDir(async (tmpDir) => {
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user