Platform specific bundle
This commit is contained in:
parent
bb6fa8ee6d
commit
d5029a8680
6 changed files with 67 additions and 14 deletions
22
lib/codeql.js
generated
22
lib/codeql.js
generated
|
|
@ -31,8 +31,23 @@ const util = __importStar(require("./util"));
|
||||||
*/
|
*/
|
||||||
let cachedCodeQL = undefined;
|
let cachedCodeQL = undefined;
|
||||||
const CODEQL_BUNDLE_VERSION = defaults.bundleVersion;
|
const CODEQL_BUNDLE_VERSION = defaults.bundleVersion;
|
||||||
const CODEQL_BUNDLE_NAME = "codeql-bundle.tar.gz";
|
|
||||||
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||||
|
function getCodeQLBundleName() {
|
||||||
|
let platform;
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
platform = "win64";
|
||||||
|
}
|
||||||
|
else if (process.platform === "linux") {
|
||||||
|
platform = "linux64";
|
||||||
|
}
|
||||||
|
else if (process.platform === "darwin") {
|
||||||
|
platform = "osx64";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "codeql-bundle.tar.gz";
|
||||||
|
}
|
||||||
|
return `codeql-bundle-${platform}.tar.gz`;
|
||||||
|
}
|
||||||
function getCodeQLActionRepository(mode) {
|
function getCodeQLActionRepository(mode) {
|
||||||
if (mode !== "actions") {
|
if (mode !== "actions") {
|
||||||
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
||||||
|
|
@ -65,6 +80,7 @@ async function getCodeQLBundleDownloadURL(githubAuth, githubUrl, mode, logger) {
|
||||||
// We now filter out any duplicates.
|
// We now filter out any duplicates.
|
||||||
// Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork.
|
// Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork.
|
||||||
const uniqueDownloadSources = potentialDownloadSources.filter((url, index, self) => index === self.indexOf(url));
|
const uniqueDownloadSources = potentialDownloadSources.filter((url, index, self) => index === self.indexOf(url));
|
||||||
|
const codeQLBundleName = getCodeQLBundleName();
|
||||||
for (const downloadSource of uniqueDownloadSources) {
|
for (const downloadSource of uniqueDownloadSources) {
|
||||||
const [apiURL, repository] = downloadSource;
|
const [apiURL, repository] = downloadSource;
|
||||||
// If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
|
// If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
|
||||||
|
|
@ -82,7 +98,7 @@ async function getCodeQLBundleDownloadURL(githubAuth, githubUrl, mode, logger) {
|
||||||
tag: CODEQL_BUNDLE_VERSION,
|
tag: CODEQL_BUNDLE_VERSION,
|
||||||
});
|
});
|
||||||
for (const asset of release.data.assets) {
|
for (const asset of release.data.assets) {
|
||||||
if (asset.name === CODEQL_BUNDLE_NAME) {
|
if (asset.name === codeQLBundleName) {
|
||||||
logger.info(`Found CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} with URL ${asset.url}.`);
|
logger.info(`Found CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} with URL ${asset.url}.`);
|
||||||
return asset.url;
|
return asset.url;
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +108,7 @@ async function getCodeQLBundleDownloadURL(githubAuth, githubUrl, mode, logger) {
|
||||||
logger.info(`Looked for CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} but got error ${e}.`);
|
logger.info(`Looked for CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} but got error ${e}.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_BUNDLE_VERSION}/${CODEQL_BUNDLE_NAME}`;
|
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_BUNDLE_VERSION}/${codeQLBundleName}`;
|
||||||
}
|
}
|
||||||
// We have to download CodeQL manually because the toolcache doesn't support Accept headers.
|
// We have to download CodeQL manually because the toolcache doesn't support Accept headers.
|
||||||
// This can be removed once https://github.com/actions/toolkit/pull/530 is merged and released.
|
// This can be removed once https://github.com/actions/toolkit/pull/530 is merged and released.
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
16
lib/codeql.test.js
generated
16
lib/codeql.test.js
generated
|
|
@ -68,23 +68,33 @@ ava_1.default("download codeql bundle cache with different version cached (not p
|
||||||
.replyWithFile(200, path.join(__dirname, `/../src/testdata/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", logging_1.getRunnerLogger(true));
|
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", "token", "https://github.com", tmpDir, tmpDir, "runner", logging_1.getRunnerLogger(true));
|
||||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||||
|
const platform = process.platform === "win32"
|
||||||
|
? "win64"
|
||||||
|
: process.platform === "linux"
|
||||||
|
? "linux64"
|
||||||
|
: "osx64";
|
||||||
nock_1.default("https://github.com")
|
nock_1.default("https://github.com")
|
||||||
.get(`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle.tar.gz`)
|
.get(`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle-${platform}.tar.gz`)
|
||||||
.replyWithFile(200, path.join(__dirname, `/../src/testdata/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", logging_1.getRunnerLogger(true));
|
await codeql.setupCodeQL(undefined, "token", "https://github.com", tmpDir, tmpDir, "runner", logging_1.getRunnerLogger(true));
|
||||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||||
t.is(cachedVersions.length, 2);
|
t.is(cachedVersions.length, 2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ava_1.default('download codeql bundle cache with pinned different version cached if "latests" tools specied', async (t) => {
|
ava_1.default('download codeql bundle cache with pinned different version cached if "latests" tools specified', async (t) => {
|
||||||
await util.withTmpDir(async (tmpDir) => {
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
nock_1.default("https://example.com")
|
nock_1.default("https://example.com")
|
||||||
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
|
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
|
||||||
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle-pinned.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", logging_1.getRunnerLogger(true));
|
await codeql.setupCodeQL("https://example.com/download/codeql-bundle-20200601/codeql-bundle.tar.gz", "token", "https://github.com", tmpDir, tmpDir, "runner", logging_1.getRunnerLogger(true));
|
||||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||||
|
const platform = process.platform === "win32"
|
||||||
|
? "win64"
|
||||||
|
: process.platform === "linux"
|
||||||
|
? "linux64"
|
||||||
|
: "osx64";
|
||||||
nock_1.default("https://github.com")
|
nock_1.default("https://github.com")
|
||||||
.get(`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle.tar.gz`)
|
.get(`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle-${platform}.tar.gz`)
|
||||||
.replyWithFile(200, path.join(__dirname, `/../src/testdata/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", logging_1.getRunnerLogger(true));
|
await codeql.setupCodeQL("latest", "token", "https://github.com", tmpDir, tmpDir, "runner", logging_1.getRunnerLogger(true));
|
||||||
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
const cachedVersions = toolcache.findAllVersions("CodeQL");
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -143,10 +143,16 @@ test("download codeql bundle cache with different version cached (not pinned)",
|
||||||
);
|
);
|
||||||
|
|
||||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||||
|
const platform =
|
||||||
|
process.platform === "win32"
|
||||||
|
? "win64"
|
||||||
|
: process.platform === "linux"
|
||||||
|
? "linux64"
|
||||||
|
: "osx64";
|
||||||
|
|
||||||
nock("https://github.com")
|
nock("https://github.com")
|
||||||
.get(
|
.get(
|
||||||
`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle.tar.gz`
|
`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle-${platform}.tar.gz`
|
||||||
)
|
)
|
||||||
.replyWithFile(
|
.replyWithFile(
|
||||||
200,
|
200,
|
||||||
|
|
@ -169,7 +175,7 @@ test("download codeql bundle cache with different version cached (not pinned)",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('download codeql bundle cache with pinned different version cached if "latests" tools specied', async (t) => {
|
test('download codeql bundle cache with pinned different version cached if "latests" tools specified', async (t) => {
|
||||||
await util.withTmpDir(async (tmpDir) => {
|
await util.withTmpDir(async (tmpDir) => {
|
||||||
nock("https://example.com")
|
nock("https://example.com")
|
||||||
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
|
.get(`/download/codeql-bundle-20200601/codeql-bundle.tar.gz`)
|
||||||
|
|
@ -190,9 +196,16 @@ test('download codeql bundle cache with pinned different version cached if "late
|
||||||
|
|
||||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
t.assert(toolcache.find("CodeQL", "0.0.0-20200601"));
|
||||||
|
|
||||||
|
const platform =
|
||||||
|
process.platform === "win32"
|
||||||
|
? "win64"
|
||||||
|
: process.platform === "linux"
|
||||||
|
? "linux64"
|
||||||
|
: "osx64";
|
||||||
|
|
||||||
nock("https://github.com")
|
nock("https://github.com")
|
||||||
.get(
|
.get(
|
||||||
`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle.tar.gz`
|
`/github/codeql-action/releases/download/${defaults.bundleVersion}/codeql-bundle-${platform}.tar.gz`
|
||||||
)
|
)
|
||||||
.replyWithFile(
|
.replyWithFile(
|
||||||
200,
|
200,
|
||||||
|
|
|
||||||
|
|
@ -115,9 +115,22 @@ export interface ResolveQueriesOutput {
|
||||||
let cachedCodeQL: CodeQL | undefined = undefined;
|
let cachedCodeQL: CodeQL | undefined = undefined;
|
||||||
|
|
||||||
const CODEQL_BUNDLE_VERSION = defaults.bundleVersion;
|
const CODEQL_BUNDLE_VERSION = defaults.bundleVersion;
|
||||||
const CODEQL_BUNDLE_NAME = "codeql-bundle.tar.gz";
|
|
||||||
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||||
|
|
||||||
|
function getCodeQLBundleName(): string {
|
||||||
|
let platform: string;
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
platform = "win64";
|
||||||
|
} else if (process.platform === "linux") {
|
||||||
|
platform = "linux64";
|
||||||
|
} else if (process.platform === "darwin") {
|
||||||
|
platform = "osx64";
|
||||||
|
} else {
|
||||||
|
return "codeql-bundle.tar.gz";
|
||||||
|
}
|
||||||
|
return `codeql-bundle-${platform}.tar.gz`;
|
||||||
|
}
|
||||||
|
|
||||||
function getCodeQLActionRepository(mode: util.Mode): string {
|
function getCodeQLActionRepository(mode: util.Mode): string {
|
||||||
if (mode !== "actions") {
|
if (mode !== "actions") {
|
||||||
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
||||||
|
|
@ -161,6 +174,7 @@ async function getCodeQLBundleDownloadURL(
|
||||||
const uniqueDownloadSources = potentialDownloadSources.filter(
|
const uniqueDownloadSources = potentialDownloadSources.filter(
|
||||||
(url, index, self) => index === self.indexOf(url)
|
(url, index, self) => index === self.indexOf(url)
|
||||||
);
|
);
|
||||||
|
const codeQLBundleName = getCodeQLBundleName();
|
||||||
for (const downloadSource of uniqueDownloadSources) {
|
for (const downloadSource of uniqueDownloadSources) {
|
||||||
const [apiURL, repository] = downloadSource;
|
const [apiURL, repository] = downloadSource;
|
||||||
// If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
|
// If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
|
||||||
|
|
@ -180,7 +194,7 @@ async function getCodeQLBundleDownloadURL(
|
||||||
tag: CODEQL_BUNDLE_VERSION,
|
tag: CODEQL_BUNDLE_VERSION,
|
||||||
});
|
});
|
||||||
for (const asset of release.data.assets) {
|
for (const asset of release.data.assets) {
|
||||||
if (asset.name === CODEQL_BUNDLE_NAME) {
|
if (asset.name === codeQLBundleName) {
|
||||||
logger.info(
|
logger.info(
|
||||||
`Found CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} with URL ${asset.url}.`
|
`Found CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} with URL ${asset.url}.`
|
||||||
);
|
);
|
||||||
|
|
@ -193,7 +207,7 @@ async function getCodeQLBundleDownloadURL(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_BUNDLE_VERSION}/${CODEQL_BUNDLE_NAME}`;
|
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_BUNDLE_VERSION}/${codeQLBundleName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have to download CodeQL manually because the toolcache doesn't support Accept headers.
|
// We have to download CodeQL manually because the toolcache doesn't support Accept headers.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue