mirror of
https://github.com/github/codeql-action.git
synced 2025-12-24 08:10:06 +08:00
Allowing a cached version of the CodeQL bundle sometimes
To save time downloading the CodeQL bundle we're pre-downloading it into the hosted Actions runner, but because the release schedule is different there may be some version drift. This change allows a different version of the bundle to be used than the default if a version isn't explicitly specified, there's only one version downloaded, and it's been marked as a 'pinned-version' - otherwise it reverts to the prior behavior.
This commit is contained in:
@@ -7,6 +7,7 @@ import * as codeql from "./codeql";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import * as util from "./util";
|
||||
import * as defaults from "./defaults.json";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
@@ -43,6 +44,177 @@ test("download codeql bundle cache", async (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
test("download codeql bundle cache explicitly requested with pinned different version cached", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
nock("https://example.com")
|
||||
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
|
||||
.replyWithFile(
|
||||
200,
|
||||
path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`)
|
||||
);
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
"https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz",
|
||||
"token",
|
||||
"https://github.com",
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
"runner",
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
|
||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||
|
||||
nock("https://example.com")
|
||||
.get(`/download/codeql-bundle-20200610/codeql-bundle.tar.gz`)
|
||||
.replyWithFile(
|
||||
200,
|
||||
path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`)
|
||||
);
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
"https://example.com/download/codeql-bundle-20200610/codeql-bundle.tar.gz",
|
||||
"token",
|
||||
"https://github.com",
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
"runner",
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
|
||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
|
||||
});
|
||||
});
|
||||
|
||||
test("don't download codeql bundle cache with pinned different version cached", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
nock("https://example.com")
|
||||
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
|
||||
.replyWithFile(
|
||||
200,
|
||||
path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`)
|
||||
);
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
"https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz",
|
||||
"token",
|
||||
"https://github.com",
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
"runner",
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
|
||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
undefined,
|
||||
"token",
|
||||
"https://github.com",
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
"runner",
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
|
||||
t.is(cachedVersions.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
test("download codeql bundle cache with different version cached (not pinned)", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
nock("https://example.com")
|
||||
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
|
||||
.replyWithFile(
|
||||
200,
|
||||
path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`)
|
||||
);
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
"https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz",
|
||||
"token",
|
||||
"https://github.com",
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
"runner",
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
|
||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||
|
||||
nock("https://github.com")
|
||||
.get(
|
||||
`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle.tar.gz`
|
||||
)
|
||||
.replyWithFile(
|
||||
200,
|
||||
path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`)
|
||||
);
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
undefined,
|
||||
"token",
|
||||
"https://github.com",
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
"runner",
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
|
||||
t.is(cachedVersions.length, 2);
|
||||
});
|
||||
});
|
||||
|
||||
test('download codeql bundle cache with pinned different version cached if "latests" tools specied', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
nock("https://example.com")
|
||||
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
|
||||
.replyWithFile(
|
||||
200,
|
||||
path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.tar.gz`)
|
||||
);
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
"https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz",
|
||||
"token",
|
||||
"https://github.com",
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
"runner",
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
|
||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||
|
||||
nock("https://github.com")
|
||||
.get(
|
||||
`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle.tar.gz`
|
||||
)
|
||||
.replyWithFile(
|
||||
200,
|
||||
path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`)
|
||||
);
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
"latest",
|
||||
"token",
|
||||
"https://github.com",
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
"runner",
|
||||
getRunnerLogger(true)
|
||||
);
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||
|
||||
t.is(cachedVersions.length, 2);
|
||||
});
|
||||
});
|
||||
|
||||
test("parse codeql bundle url version", (t) => {
|
||||
const tests = {
|
||||
"20200601": "0.0.0-20200601",
|
||||
|
||||
Reference in New Issue
Block a user