Extract directly to toolcache when feature enabled
This commit is contained in:
parent
6695503422
commit
198fb4b4b2
15 changed files with 175 additions and 153 deletions
2
lib/codeql.js
generated
2
lib/codeql.js
generated
|
|
@ -136,7 +136,7 @@ async function setupCodeQL(toolsInput, apiDetails, tempDir, variant, defaultCliV
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
throw new Error(`Unable to download and extract CodeQL CLI: ${(0, util_1.getErrorMessage)(e)}`);
|
throw new Error(`Unable to download and extract CodeQL CLI: ${(0, util_1.getErrorMessage)(e)}${e instanceof Error && e.stack ? `\n\nDetails: ${e.stack}` : ""}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
35
lib/codeql.test.js
generated
35
lib/codeql.test.js
generated
|
|
@ -41,7 +41,6 @@ const cli_errors_1 = require("./cli-errors");
|
||||||
const codeql = __importStar(require("./codeql"));
|
const codeql = __importStar(require("./codeql"));
|
||||||
const defaults = __importStar(require("./defaults.json"));
|
const defaults = __importStar(require("./defaults.json"));
|
||||||
const doc_url_1 = require("./doc-url");
|
const doc_url_1 = require("./doc-url");
|
||||||
const feature_flags_test_1 = require("./feature-flags.test");
|
|
||||||
const languages_1 = require("./languages");
|
const languages_1 = require("./languages");
|
||||||
const logging_1 = require("./logging");
|
const logging_1 = require("./logging");
|
||||||
const setup_codeql_1 = require("./setup-codeql");
|
const setup_codeql_1 = require("./setup-codeql");
|
||||||
|
|
@ -51,12 +50,7 @@ const util = __importStar(require("./util"));
|
||||||
const util_1 = require("./util");
|
const util_1 = require("./util");
|
||||||
(0, testing_utils_1.setupTests)(ava_1.default);
|
(0, testing_utils_1.setupTests)(ava_1.default);
|
||||||
let stubConfig;
|
let stubConfig;
|
||||||
// TODO: Remove when when we no longer need to pass in features (https://github.com/github/codeql-action/issues/2600)
|
const NO_FEATURES = (0, testing_utils_1.createFeatures)([]);
|
||||||
const expectedFeatureEnablement = (0, feature_flags_test_1.initializeFeatures)(true);
|
|
||||||
expectedFeatureEnablement.getValue = function (feature) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
||||||
return expectedFeatureEnablement[feature];
|
|
||||||
};
|
|
||||||
ava_1.default.beforeEach(() => {
|
ava_1.default.beforeEach(() => {
|
||||||
(0, util_1.initializeEnvironment)("1.2.3");
|
(0, util_1.initializeEnvironment)("1.2.3");
|
||||||
stubConfig = (0, testing_utils_1.createTestConfig)({
|
stubConfig = (0, testing_utils_1.createTestConfig)({
|
||||||
|
|
@ -67,7 +61,7 @@ async function installIntoToolcache({ apiDetails = testing_utils_1.SAMPLE_DOTCOM
|
||||||
const url = (0, testing_utils_1.mockBundleDownloadApi)({ apiDetails, isPinned, tagName });
|
const url = (0, testing_utils_1.mockBundleDownloadApi)({ apiDetails, isPinned, tagName });
|
||||||
await codeql.setupCodeQL(cliVersion !== undefined ? undefined : url, apiDetails, tmpDir, util.GitHubVariant.GHES, cliVersion !== undefined
|
await codeql.setupCodeQL(cliVersion !== undefined ? undefined : url, apiDetails, tmpDir, util.GitHubVariant.GHES, cliVersion !== undefined
|
||||||
? { cliVersion, tagName }
|
? { cliVersion, tagName }
|
||||||
: testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
: testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
}
|
}
|
||||||
function mockReleaseApi({ apiDetails = testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, assetNames, tagName, }) {
|
function mockReleaseApi({ apiDetails = testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, assetNames, tagName, }) {
|
||||||
return (0, nock_1.default)(apiDetails.apiURL)
|
return (0, nock_1.default)(apiDetails.apiURL)
|
||||||
|
|
@ -88,11 +82,8 @@ function mockApiDetails(apiDetails) {
|
||||||
.stub(actionsUtil, "getRequiredInput")
|
.stub(actionsUtil, "getRequiredInput")
|
||||||
.withArgs("token")
|
.withArgs("token")
|
||||||
.returns(apiDetails.auth);
|
.returns(apiDetails.auth);
|
||||||
const requiredEnvParamStub = sinon.stub(util, "getRequiredEnvParam");
|
process.env["GITHUB_SERVER_URL"] = apiDetails.url;
|
||||||
requiredEnvParamStub.withArgs("GITHUB_SERVER_URL").returns(apiDetails.url);
|
process.env["GITHUB_API_URL"] = apiDetails.apiURL || "";
|
||||||
requiredEnvParamStub
|
|
||||||
.withArgs("GITHUB_API_URL")
|
|
||||||
.returns(apiDetails.apiURL || "");
|
|
||||||
}
|
}
|
||||||
(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) => {
|
||||||
|
|
@ -104,7 +95,7 @@ function mockApiDetails(apiDetails) {
|
||||||
tagName: `codeql-bundle-${version}`,
|
tagName: `codeql-bundle-${version}`,
|
||||||
isPinned: false,
|
isPinned: false,
|
||||||
});
|
});
|
||||||
const result = await codeql.setupCodeQL(url, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
const result = await codeql.setupCodeQL(url, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
t.assert(toolcache.find("CodeQL", `0.0.0-${version}`));
|
t.assert(toolcache.find("CodeQL", `0.0.0-${version}`));
|
||||||
t.is(result.toolsVersion, `0.0.0-${version}`);
|
t.is(result.toolsVersion, `0.0.0-${version}`);
|
||||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||||
|
|
@ -119,7 +110,7 @@ function mockApiDetails(apiDetails) {
|
||||||
tagName: `codeql-bundle-v2.15.0`,
|
tagName: `codeql-bundle-v2.15.0`,
|
||||||
isPinned: false,
|
isPinned: false,
|
||||||
});
|
});
|
||||||
const result = await codeql.setupCodeQL(url, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
const result = await codeql.setupCodeQL(url, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
t.is(toolcache.findAllVersions("CodeQL").length, 1);
|
t.is(toolcache.findAllVersions("CodeQL").length, 1);
|
||||||
t.assert(toolcache.find("CodeQL", `2.15.0`));
|
t.assert(toolcache.find("CodeQL", `2.15.0`));
|
||||||
t.is(result.toolsVersion, `2.15.0`);
|
t.is(result.toolsVersion, `2.15.0`);
|
||||||
|
|
@ -140,7 +131,7 @@ function mockApiDetails(apiDetails) {
|
||||||
const url = (0, testing_utils_1.mockBundleDownloadApi)({
|
const url = (0, testing_utils_1.mockBundleDownloadApi)({
|
||||||
tagName: "codeql-bundle-20200610",
|
tagName: "codeql-bundle-20200610",
|
||||||
});
|
});
|
||||||
const result = await codeql.setupCodeQL(url, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
const result = await codeql.setupCodeQL(url, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
|
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
|
||||||
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
t.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
||||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||||
|
|
@ -168,7 +159,7 @@ for (const { tagName, expectedToolcacheVersion, } of EXPLICITLY_REQUESTED_BUNDLE
|
||||||
const url = (0, testing_utils_1.mockBundleDownloadApi)({
|
const url = (0, testing_utils_1.mockBundleDownloadApi)({
|
||||||
tagName,
|
tagName,
|
||||||
});
|
});
|
||||||
const result = await codeql.setupCodeQL(url, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
const result = await codeql.setupCodeQL(url, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
t.assert(toolcache.find("CodeQL", expectedToolcacheVersion));
|
t.assert(toolcache.find("CodeQL", expectedToolcacheVersion));
|
||||||
t.deepEqual(result.toolsVersion, expectedToolcacheVersion);
|
t.deepEqual(result.toolsVersion, expectedToolcacheVersion);
|
||||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||||
|
|
@ -191,7 +182,7 @@ for (const toolcacheVersion of [
|
||||||
.withArgs("CodeQL", toolcacheVersion)
|
.withArgs("CodeQL", toolcacheVersion)
|
||||||
.returns("path/to/cached/codeql");
|
.returns("path/to/cached/codeql");
|
||||||
sinon.stub(toolcache, "findAllVersions").returns([toolcacheVersion]);
|
sinon.stub(toolcache, "findAllVersions").returns([toolcacheVersion]);
|
||||||
const result = await codeql.setupCodeQL(undefined, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
const result = await codeql.setupCodeQL(undefined, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
t.is(result.toolsVersion, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION.cliVersion);
|
t.is(result.toolsVersion, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION.cliVersion);
|
||||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Toolcache);
|
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Toolcache);
|
||||||
t.is(result.toolsDownloadStatusReport?.combinedDurationMs, undefined);
|
t.is(result.toolsDownloadStatusReport?.combinedDurationMs, undefined);
|
||||||
|
|
@ -211,7 +202,7 @@ for (const toolcacheVersion of [
|
||||||
const result = await codeql.setupCodeQL(undefined, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.GHES, {
|
const result = await codeql.setupCodeQL(undefined, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.GHES, {
|
||||||
cliVersion: defaults.cliVersion,
|
cliVersion: defaults.cliVersion,
|
||||||
tagName: defaults.bundleVersion,
|
tagName: defaults.bundleVersion,
|
||||||
}, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
}, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
t.deepEqual(result.toolsVersion, "0.0.0-20200601");
|
t.deepEqual(result.toolsVersion, "0.0.0-20200601");
|
||||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Toolcache);
|
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Toolcache);
|
||||||
t.is(result.toolsDownloadStatusReport?.combinedDurationMs, undefined);
|
t.is(result.toolsDownloadStatusReport?.combinedDurationMs, undefined);
|
||||||
|
|
@ -235,7 +226,7 @@ for (const toolcacheVersion of [
|
||||||
const result = await codeql.setupCodeQL(undefined, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.GHES, {
|
const result = await codeql.setupCodeQL(undefined, testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.GHES, {
|
||||||
cliVersion: defaults.cliVersion,
|
cliVersion: defaults.cliVersion,
|
||||||
tagName: defaults.bundleVersion,
|
tagName: defaults.bundleVersion,
|
||||||
}, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
}, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
||||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||||
if (result.toolsDownloadStatusReport) {
|
if (result.toolsDownloadStatusReport) {
|
||||||
|
|
@ -256,7 +247,7 @@ for (const toolcacheVersion of [
|
||||||
(0, testing_utils_1.mockBundleDownloadApi)({
|
(0, testing_utils_1.mockBundleDownloadApi)({
|
||||||
tagName: defaults.bundleVersion,
|
tagName: defaults.bundleVersion,
|
||||||
});
|
});
|
||||||
const result = await codeql.setupCodeQL("latest", testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
const result = await codeql.setupCodeQL("latest", testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
||||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||||
if (result.toolsDownloadStatusReport) {
|
if (result.toolsDownloadStatusReport) {
|
||||||
|
|
@ -280,7 +271,7 @@ for (const toolcacheVersion of [
|
||||||
platformSpecific: false,
|
platformSpecific: false,
|
||||||
tagName: "codeql-bundle-20230203",
|
tagName: "codeql-bundle-20230203",
|
||||||
});
|
});
|
||||||
const result = await codeql.setupCodeQL("https://github.com/codeql-testing/codeql-cli-nightlies/releases/download/codeql-bundle-20230203/codeql-bundle.tar.gz", testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), expectedFeatureEnablement, false);
|
const result = await codeql.setupCodeQL("https://github.com/codeql-testing/codeql-cli-nightlies/releases/download/codeql-bundle-20230203/codeql-bundle.tar.gz", testing_utils_1.SAMPLE_DOTCOM_API_DETAILS, tmpDir, util.GitHubVariant.DOTCOM, testing_utils_1.SAMPLE_DEFAULT_CLI_VERSION, (0, logging_1.getRunnerLogger)(true), NO_FEATURES, false);
|
||||||
t.is(result.toolsVersion, "0.0.0-20230203");
|
t.is(result.toolsVersion, "0.0.0-20230203");
|
||||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||||
if (result.toolsDownloadStatusReport) {
|
if (result.toolsDownloadStatusReport) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
31
lib/setup-codeql.js
generated
31
lib/setup-codeql.js
generated
|
|
@ -41,6 +41,7 @@ const perf_hooks_1 = require("perf_hooks");
|
||||||
const toolcache = __importStar(require("@actions/tool-cache"));
|
const toolcache = __importStar(require("@actions/tool-cache"));
|
||||||
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
||||||
const semver = __importStar(require("semver"));
|
const semver = __importStar(require("semver"));
|
||||||
|
const uuid_1 = require("uuid");
|
||||||
const actions_util_1 = require("./actions-util");
|
const actions_util_1 = require("./actions-util");
|
||||||
const api = __importStar(require("./api-client"));
|
const api = __importStar(require("./api-client"));
|
||||||
const defaults = __importStar(require("./defaults.json"));
|
const defaults = __importStar(require("./defaults.json"));
|
||||||
|
|
@ -401,9 +402,13 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
|
||||||
else {
|
else {
|
||||||
logger.debug("Downloading CodeQL tools without an authorization token.");
|
logger.debug("Downloading CodeQL tools without an authorization token.");
|
||||||
}
|
}
|
||||||
const { extractedBundlePath, statusReport } = await (0, tools_download_1.downloadAndExtract)(codeqlURL, authorization, { "User-Agent": "CodeQL Action", ...headers }, tarVersion, tempDir, features, logger);
|
const toolcacheInfo = getToolcacheDestinationInfo(maybeBundleVersion, maybeCliVersion, logger);
|
||||||
const bundleVersion = maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
|
const extractToToolcache = !!toolcacheInfo && !!(await features.getValue(feature_flags_1.Feature.ExtractToToolcache));
|
||||||
if (bundleVersion === undefined) {
|
const extractedBundlePath = extractToToolcache
|
||||||
|
? toolcacheInfo.path
|
||||||
|
: getTempExtractionDir(tempDir);
|
||||||
|
const statusReport = await (0, tools_download_1.downloadAndExtract)(codeqlURL, extractedBundlePath, authorization, { "User-Agent": "CodeQL Action", ...headers }, tarVersion, features, logger);
|
||||||
|
if (!toolcacheInfo) {
|
||||||
logger.debug("Could not cache CodeQL tools because we could not determine the bundle version from the " +
|
logger.debug("Could not cache CodeQL tools because we could not determine the bundle version from the " +
|
||||||
`URL ${codeqlURL}.`);
|
`URL ${codeqlURL}.`);
|
||||||
return {
|
return {
|
||||||
|
|
@ -413,9 +418,8 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
logger.debug("Caching CodeQL bundle.");
|
logger.debug("Caching CodeQL bundle.");
|
||||||
const toolcacheVersion = getCanonicalToolcacheVersion(maybeCliVersion, bundleVersion, logger);
|
|
||||||
const toolcacheStart = perf_hooks_1.performance.now();
|
const toolcacheStart = perf_hooks_1.performance.now();
|
||||||
const toolcachedBundlePath = await toolcache.cacheDir(extractedBundlePath, "CodeQL", toolcacheVersion);
|
const toolcachedBundlePath = await toolcache.cacheDir(extractedBundlePath, "CodeQL", toolcacheInfo.version);
|
||||||
logger.info(`Added CodeQL bundle to the tool cache (${(0, logging_1.formatDuration)(perf_hooks_1.performance.now() - toolcacheStart)}).`);
|
logger.info(`Added CodeQL bundle to the tool cache (${(0, logging_1.formatDuration)(perf_hooks_1.performance.now() - toolcacheStart)}).`);
|
||||||
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
|
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
|
||||||
if (toolcachedBundlePath !== extractedBundlePath) {
|
if (toolcachedBundlePath !== extractedBundlePath) {
|
||||||
|
|
@ -424,10 +428,20 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
|
||||||
return {
|
return {
|
||||||
codeqlFolder: toolcachedBundlePath,
|
codeqlFolder: toolcachedBundlePath,
|
||||||
statusReport,
|
statusReport,
|
||||||
toolsVersion: maybeCliVersion ?? toolcacheVersion,
|
toolsVersion: maybeCliVersion ?? toolcacheInfo.version,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
exports.downloadCodeQL = downloadCodeQL;
|
exports.downloadCodeQL = downloadCodeQL;
|
||||||
|
function getToolcacheDestinationInfo(maybeBundleVersion, maybeCliVersion, logger) {
|
||||||
|
if (maybeBundleVersion) {
|
||||||
|
const version = getCanonicalToolcacheVersion(maybeCliVersion, maybeBundleVersion, logger);
|
||||||
|
return {
|
||||||
|
path: (0, tools_download_1.getToolcacheDirectory)(version),
|
||||||
|
version,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
function getCodeQLURLVersion(url) {
|
function getCodeQLURLVersion(url) {
|
||||||
const match = url.match(/\/codeql-bundle-(.*)\//);
|
const match = url.match(/\/codeql-bundle-(.*)\//);
|
||||||
if (match === null || match.length < 2) {
|
if (match === null || match.length < 2) {
|
||||||
|
|
@ -475,7 +489,7 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, featu
|
||||||
switch (source.sourceType) {
|
switch (source.sourceType) {
|
||||||
case "local": {
|
case "local": {
|
||||||
const compressionMethod = tar.inferCompressionMethod(source.codeqlTarPath);
|
const compressionMethod = tar.inferCompressionMethod(source.codeqlTarPath);
|
||||||
codeqlFolder = await tar.extract(source.codeqlTarPath, compressionMethod, zstdAvailability.version, logger);
|
codeqlFolder = await tar.extract(source.codeqlTarPath, getTempExtractionDir(tempDir), compressionMethod, zstdAvailability.version, logger);
|
||||||
toolsSource = ToolsSource.Local;
|
toolsSource = ToolsSource.Local;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -510,4 +524,7 @@ async function useZstdBundle(cliVersion, tarSupportsZstd) {
|
||||||
tarSupportsZstd &&
|
tarSupportsZstd &&
|
||||||
semver.gte(cliVersion, feature_flags_1.CODEQL_VERSION_ZSTD_BUNDLE));
|
semver.gte(cliVersion, feature_flags_1.CODEQL_VERSION_ZSTD_BUNDLE));
|
||||||
}
|
}
|
||||||
|
function getTempExtractionDir(tempDir) {
|
||||||
|
return path.join(tempDir, (0, uuid_1.v4)());
|
||||||
|
}
|
||||||
//# sourceMappingURL=setup-codeql.js.map
|
//# sourceMappingURL=setup-codeql.js.map
|
||||||
File diff suppressed because one or more lines are too long
18
lib/tar.js
generated
18
lib/tar.js
generated
|
|
@ -22,23 +22,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
__setModuleDefault(result, mod);
|
__setModuleDefault(result, mod);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.isZstdAvailable = isZstdAvailable;
|
exports.isZstdAvailable = isZstdAvailable;
|
||||||
exports.extract = extract;
|
exports.extract = extract;
|
||||||
exports.extractTarZst = extractTarZst;
|
exports.extractTarZst = extractTarZst;
|
||||||
exports.createExtractFolder = createExtractFolder;
|
|
||||||
exports.inferCompressionMethod = inferCompressionMethod;
|
exports.inferCompressionMethod = inferCompressionMethod;
|
||||||
const child_process_1 = require("child_process");
|
const child_process_1 = require("child_process");
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const path_1 = __importDefault(require("path"));
|
|
||||||
const stream = __importStar(require("stream"));
|
const stream = __importStar(require("stream"));
|
||||||
const toolrunner_1 = require("@actions/exec/lib/toolrunner");
|
const toolrunner_1 = require("@actions/exec/lib/toolrunner");
|
||||||
const toolcache = __importStar(require("@actions/tool-cache"));
|
const toolcache = __importStar(require("@actions/tool-cache"));
|
||||||
const safe_which_1 = require("@chrisgavin/safe-which");
|
const safe_which_1 = require("@chrisgavin/safe-which");
|
||||||
const uuid_1 = require("uuid");
|
|
||||||
const actions_util_1 = require("./actions-util");
|
const actions_util_1 = require("./actions-util");
|
||||||
const util_1 = require("./util");
|
const util_1 = require("./util");
|
||||||
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
|
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
|
||||||
|
|
@ -104,17 +98,18 @@ async function isZstdAvailable(logger) {
|
||||||
return { available: false, foundZstdBinary };
|
return { available: false, foundZstdBinary };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function extract(tarPath, compressionMethod, tarVersion, logger) {
|
async function extract(tarPath, dest, compressionMethod, tarVersion, logger) {
|
||||||
|
// Ensure destination exists
|
||||||
|
fs.mkdirSync(dest, { recursive: true });
|
||||||
switch (compressionMethod) {
|
switch (compressionMethod) {
|
||||||
case "gzip":
|
case "gzip":
|
||||||
// Defensively continue to call the toolcache API as requesting a gzipped
|
// Defensively continue to call the toolcache API as requesting a gzipped
|
||||||
// bundle may be a fallback option.
|
// bundle may be a fallback option.
|
||||||
return await toolcache.extractTar(tarPath);
|
return await toolcache.extractTar(tarPath, dest);
|
||||||
case "zstd": {
|
case "zstd": {
|
||||||
if (!tarVersion) {
|
if (!tarVersion) {
|
||||||
throw new Error("Could not determine tar version, which is required to extract a Zstandard archive.");
|
throw new Error("Could not determine tar version, which is required to extract a Zstandard archive.");
|
||||||
}
|
}
|
||||||
const dest = await createExtractFolder();
|
|
||||||
await extractTarZst(tarPath, dest, tarVersion, logger);
|
await extractTarZst(tarPath, dest, tarVersion, logger);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
@ -169,11 +164,6 @@ async function extractTarZst(tar, dest, tarVersion, logger) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function createExtractFolder() {
|
|
||||||
const dest = path_1.default.join((0, actions_util_1.getTemporaryDirectory)(), (0, uuid_1.v4)());
|
|
||||||
fs.mkdirSync(dest, { recursive: true });
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
function inferCompressionMethod(tarPath) {
|
function inferCompressionMethod(tarPath) {
|
||||||
if (tarPath.endsWith(".tar.gz")) {
|
if (tarPath.endsWith(".tar.gz")) {
|
||||||
return "gzip";
|
return "gzip";
|
||||||
|
|
|
||||||
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lib/tools-download.js
generated
45
lib/tools-download.js
generated
|
|
@ -25,11 +25,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.STREAMING_HIGH_WATERMARK_BYTES = void 0;
|
exports.STREAMING_HIGH_WATERMARK_BYTES = void 0;
|
||||||
exports.downloadAndExtract = downloadAndExtract;
|
exports.downloadAndExtract = downloadAndExtract;
|
||||||
|
exports.getToolcacheDirectory = getToolcacheDirectory;
|
||||||
|
const os = __importStar(require("os"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const perf_hooks_1 = require("perf_hooks");
|
const perf_hooks_1 = require("perf_hooks");
|
||||||
const toolcache = __importStar(require("@actions/tool-cache"));
|
const toolcache = __importStar(require("@actions/tool-cache"));
|
||||||
const follow_redirects_1 = require("follow-redirects");
|
const follow_redirects_1 = require("follow-redirects");
|
||||||
const uuid_1 = require("uuid");
|
const semver = __importStar(require("semver"));
|
||||||
const feature_flags_1 = require("./feature-flags");
|
const feature_flags_1 = require("./feature-flags");
|
||||||
const logging_1 = require("./logging");
|
const logging_1 = require("./logging");
|
||||||
const tar = __importStar(require("./tar"));
|
const tar = __importStar(require("./tar"));
|
||||||
|
|
@ -38,6 +40,10 @@ const util_1 = require("./util");
|
||||||
* High watermark to use when streaming the download and extraction of the CodeQL tools.
|
* High watermark to use when streaming the download and extraction of the CodeQL tools.
|
||||||
*/
|
*/
|
||||||
exports.STREAMING_HIGH_WATERMARK_BYTES = 4 * 1024 * 1024; // 4 MiB
|
exports.STREAMING_HIGH_WATERMARK_BYTES = 4 * 1024 * 1024; // 4 MiB
|
||||||
|
/**
|
||||||
|
* The name of the tool cache directory for the CodeQL tools.
|
||||||
|
*/
|
||||||
|
const TOOLCACHE_TOOL_NAME = "CodeQL";
|
||||||
function makeDownloadFirstToolsDownloadDurations(downloadDurationMs, extractionDurationMs) {
|
function makeDownloadFirstToolsDownloadDurations(downloadDurationMs, extractionDurationMs) {
|
||||||
return {
|
return {
|
||||||
combinedDurationMs: downloadDurationMs + extractionDurationMs,
|
combinedDurationMs: downloadDurationMs + extractionDurationMs,
|
||||||
|
|
@ -54,7 +60,7 @@ function makeStreamedToolsDownloadDurations(combinedDurationMs) {
|
||||||
streamExtraction: true,
|
streamExtraction: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async function downloadAndExtract(codeqlURL, authorization, headers, tarVersion, tempDir, features, logger) {
|
async function downloadAndExtract(codeqlURL, dest, authorization, headers, tarVersion, features, logger) {
|
||||||
logger.info(`Downloading CodeQL tools from ${codeqlURL} . This may take a while.`);
|
logger.info(`Downloading CodeQL tools from ${codeqlURL} . This may take a while.`);
|
||||||
const compressionMethod = tar.inferCompressionMethod(codeqlURL);
|
const compressionMethod = tar.inferCompressionMethod(codeqlURL);
|
||||||
// TODO: Re-enable streaming when we have a more reliable way to respect proxy settings.
|
// TODO: Re-enable streaming when we have a more reliable way to respect proxy settings.
|
||||||
|
|
@ -63,43 +69,34 @@ async function downloadAndExtract(codeqlURL, authorization, headers, tarVersion,
|
||||||
process.platform === "linux") {
|
process.platform === "linux") {
|
||||||
logger.info(`Streaming the extraction of the CodeQL bundle.`);
|
logger.info(`Streaming the extraction of the CodeQL bundle.`);
|
||||||
const toolsInstallStart = perf_hooks_1.performance.now();
|
const toolsInstallStart = perf_hooks_1.performance.now();
|
||||||
const extractedBundlePath = await tar.createExtractFolder();
|
await downloadAndExtractZstdWithStreaming(codeqlURL, dest, authorization, headers, tarVersion, logger);
|
||||||
await downloadAndExtractZstdWithStreaming(codeqlURL, extractedBundlePath, authorization, headers, tarVersion, logger);
|
|
||||||
const combinedDurationMs = Math.round(perf_hooks_1.performance.now() - toolsInstallStart);
|
const combinedDurationMs = Math.round(perf_hooks_1.performance.now() - toolsInstallStart);
|
||||||
logger.info(`Finished downloading and extracting CodeQL bundle to ${extractedBundlePath} (${(0, logging_1.formatDuration)(combinedDurationMs)}).`);
|
logger.info(`Finished downloading and extracting CodeQL bundle to ${dest} (${(0, logging_1.formatDuration)(combinedDurationMs)}).`);
|
||||||
return {
|
return {
|
||||||
extractedBundlePath,
|
compressionMethod,
|
||||||
statusReport: {
|
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||||
compressionMethod,
|
...makeStreamedToolsDownloadDurations(combinedDurationMs),
|
||||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
|
||||||
...makeStreamedToolsDownloadDurations(combinedDurationMs),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const dest = path.join(tempDir, (0, uuid_1.v4)());
|
|
||||||
const toolsDownloadStart = perf_hooks_1.performance.now();
|
const toolsDownloadStart = perf_hooks_1.performance.now();
|
||||||
const archivedBundlePath = await toolcache.downloadTool(codeqlURL, dest, authorization, headers);
|
const archivedBundlePath = await toolcache.downloadTool(codeqlURL, undefined, authorization, headers);
|
||||||
const downloadDurationMs = Math.round(perf_hooks_1.performance.now() - toolsDownloadStart);
|
const downloadDurationMs = Math.round(perf_hooks_1.performance.now() - toolsDownloadStart);
|
||||||
logger.info(`Finished downloading CodeQL bundle to ${archivedBundlePath} (${(0, logging_1.formatDuration)(downloadDurationMs)}).`);
|
logger.info(`Finished downloading CodeQL bundle to ${archivedBundlePath} (${(0, logging_1.formatDuration)(downloadDurationMs)}).`);
|
||||||
let extractedBundlePath;
|
|
||||||
let extractionDurationMs;
|
let extractionDurationMs;
|
||||||
try {
|
try {
|
||||||
logger.info("Extracting CodeQL bundle.");
|
logger.info("Extracting CodeQL bundle.");
|
||||||
const extractionStart = perf_hooks_1.performance.now();
|
const extractionStart = perf_hooks_1.performance.now();
|
||||||
extractedBundlePath = await tar.extract(archivedBundlePath, compressionMethod, tarVersion, logger);
|
await tar.extract(archivedBundlePath, dest, compressionMethod, tarVersion, logger);
|
||||||
extractionDurationMs = Math.round(perf_hooks_1.performance.now() - extractionStart);
|
extractionDurationMs = Math.round(perf_hooks_1.performance.now() - extractionStart);
|
||||||
logger.info(`Finished extracting CodeQL bundle to ${extractedBundlePath} (${(0, logging_1.formatDuration)(extractionDurationMs)}).`);
|
logger.info(`Finished extracting CodeQL bundle to ${dest} (${(0, logging_1.formatDuration)(extractionDurationMs)}).`);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
await (0, util_1.cleanUpGlob)(archivedBundlePath, "CodeQL bundle archive", logger);
|
await (0, util_1.cleanUpGlob)(archivedBundlePath, "CodeQL bundle archive", logger);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
extractedBundlePath,
|
compressionMethod,
|
||||||
statusReport: {
|
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||||
compressionMethod,
|
...makeDownloadFirstToolsDownloadDurations(downloadDurationMs, extractionDurationMs),
|
||||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
|
||||||
...makeDownloadFirstToolsDownloadDurations(downloadDurationMs, extractionDurationMs),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async function downloadAndExtractZstdWithStreaming(codeqlURL, dest, authorization, headers, tarVersion, logger) {
|
async function downloadAndExtractZstdWithStreaming(codeqlURL, dest, authorization, headers, tarVersion, logger) {
|
||||||
|
|
@ -113,6 +110,10 @@ async function downloadAndExtractZstdWithStreaming(codeqlURL, dest, authorizatio
|
||||||
}
|
}
|
||||||
await tar.extractTarZst(response, dest, tarVersion, logger);
|
await tar.extractTarZst(response, dest, tarVersion, logger);
|
||||||
}
|
}
|
||||||
|
/** Gets the path to the toolcache directory for the specified version of the CodeQL tools. */
|
||||||
|
function getToolcacheDirectory(version) {
|
||||||
|
return path.join((0, util_1.getRequiredEnvParam)("RUNNER_TOOL_CACHE"), TOOLCACHE_TOOL_NAME, semver.clean(version) || version, os.arch() || "");
|
||||||
|
}
|
||||||
function sanitizeUrlForStatusReport(url) {
|
function sanitizeUrlForStatusReport(url) {
|
||||||
return ["github/codeql-action", "dsp-testing/codeql-cli-nightlies"].some((repo) => url.startsWith(`https://github.com/${repo}/releases/download/`))
|
return ["github/codeql-action", "dsp-testing/codeql-cli-nightlies"].some((repo) => url.startsWith(`https://github.com/${repo}/releases/download/`))
|
||||||
? url
|
? url
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"tools-download.js","sourceRoot":"","sources":["../src/tools-download.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,gDA2GC;AAnLD,2CAA6B;AAC7B,2CAAyC;AAEzC,+DAAiD;AACjD,uDAAyC;AACzC,+BAAoC;AAEpC,mDAA6D;AAC7D,uCAAmD;AACnD,2CAA6B;AAC7B,iCAAqC;AAErC;;GAEG;AACU,QAAA,8BAA8B,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,QAAQ;AAavE,SAAS,uCAAuC,CAC9C,kBAA0B,EAC1B,oBAA4B;IAE5B,OAAO;QACL,kBAAkB,EAAE,kBAAkB,GAAG,oBAAoB;QAC7D,kBAAkB;QAClB,oBAAoB;QACpB,gBAAgB,EAAE,KAAK;KACxB,CAAC;AACJ,CAAC;AAaD,SAAS,kCAAkC,CACzC,kBAA0B;IAE1B,OAAO;QACL,kBAAkB;QAClB,kBAAkB,EAAE,SAAS;QAC7B,oBAAoB,EAAE,SAAS;QAC/B,gBAAgB,EAAE,IAAI;KACvB,CAAC;AACJ,CAAC;AAYM,KAAK,UAAU,kBAAkB,CACtC,SAAiB,EACjB,aAAiC,EACjC,OAA4B,EAC5B,UAAsC,EACtC,OAAe,EACf,QAA2B,EAC3B,MAAc;IAKd,MAAM,CAAC,IAAI,CACT,iCAAiC,SAAS,2BAA2B,CACtE,CAAC;IAEF,MAAM,iBAAiB,GAAG,GAAG,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAEhE,wFAAwF;IAExF,IACE,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,uBAAO,CAAC,6BAA6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,OAAO,CAAkB,CAAC,OAAO,EAAE,EAAE,CAC9D,wBAAK,CAAC,GAAG,CACP,SAAS,EACT;QACE,OAAO;QACP,aAAa,EAAE,sCAA8B;KACjB,EAC9B,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAClB,CACF,CAAC;IAEF,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,yCAAyC,SAAS,uBAAuB,QAAQ,CAAC,UAAU,GAAG,CAChG,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AAC9D,CAAC;AAED,8FAA8F;AAC9F,SAAgB,qBAAqB,CAAC,OAAe;IACnD,OAAO,IAAI,CAAC,IAAI,CACd,IAAA,0BAAmB,EAAC,mBAAmB,CAAC,EACxC,mBAAmB,EACnB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,EAChC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,CAChB,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B,CAAC,GAAW;IAC7C,OAAO,CAAC,sBAAsB,EAAE,kCAAkC,CAAC,CAAC,IAAI,CACtE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,sBAAsB,IAAI,qBAAqB,CAAC,CAC1E;QACC,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,iBAAiB,CAAC;AACxB,CAAC"}
|
||||||
|
|
@ -17,8 +17,7 @@ import * as codeql from "./codeql";
|
||||||
import { AugmentationProperties, Config } from "./config-utils";
|
import { AugmentationProperties, Config } from "./config-utils";
|
||||||
import * as defaults from "./defaults.json";
|
import * as defaults from "./defaults.json";
|
||||||
import { DocUrl } from "./doc-url";
|
import { DocUrl } from "./doc-url";
|
||||||
import { Feature, FeatureEnablement } from "./feature-flags";
|
import { FeatureEnablement } from "./feature-flags";
|
||||||
import { initializeFeatures } from "./feature-flags.test";
|
|
||||||
import { Language } from "./languages";
|
import { Language } from "./languages";
|
||||||
import { getRunnerLogger } from "./logging";
|
import { getRunnerLogger } from "./logging";
|
||||||
import { ToolsSource } from "./setup-codeql";
|
import { ToolsSource } from "./setup-codeql";
|
||||||
|
|
@ -41,14 +40,7 @@ setupTests(test);
|
||||||
|
|
||||||
let stubConfig: Config;
|
let stubConfig: Config;
|
||||||
|
|
||||||
// TODO: Remove when when we no longer need to pass in features (https://github.com/github/codeql-action/issues/2600)
|
const NO_FEATURES: FeatureEnablement = createFeatures([]);
|
||||||
const expectedFeatureEnablement: FeatureEnablement = initializeFeatures(
|
|
||||||
true,
|
|
||||||
) as FeatureEnablement;
|
|
||||||
expectedFeatureEnablement.getValue = function (feature: Feature) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
||||||
return expectedFeatureEnablement[feature];
|
|
||||||
};
|
|
||||||
|
|
||||||
test.beforeEach(() => {
|
test.beforeEach(() => {
|
||||||
initializeEnvironment("1.2.3");
|
initializeEnvironment("1.2.3");
|
||||||
|
|
@ -81,7 +73,7 @@ async function installIntoToolcache({
|
||||||
? { cliVersion, tagName }
|
? { cliVersion, tagName }
|
||||||
: SAMPLE_DEFAULT_CLI_VERSION,
|
: SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -114,11 +106,8 @@ function mockApiDetails(apiDetails: GitHubApiDetails) {
|
||||||
.stub(actionsUtil, "getRequiredInput")
|
.stub(actionsUtil, "getRequiredInput")
|
||||||
.withArgs("token")
|
.withArgs("token")
|
||||||
.returns(apiDetails.auth);
|
.returns(apiDetails.auth);
|
||||||
const requiredEnvParamStub = sinon.stub(util, "getRequiredEnvParam");
|
process.env["GITHUB_SERVER_URL"] = apiDetails.url;
|
||||||
requiredEnvParamStub.withArgs("GITHUB_SERVER_URL").returns(apiDetails.url);
|
process.env["GITHUB_API_URL"] = apiDetails.apiURL || "";
|
||||||
requiredEnvParamStub
|
|
||||||
.withArgs("GITHUB_API_URL")
|
|
||||||
.returns(apiDetails.apiURL || "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test("downloads and caches explicitly requested bundles that aren't in the toolcache", async (t) => {
|
test("downloads and caches explicitly requested bundles that aren't in the toolcache", async (t) => {
|
||||||
|
|
@ -141,7 +130,7 @@ test("downloads and caches explicitly requested bundles that aren't in the toolc
|
||||||
util.GitHubVariant.DOTCOM,
|
util.GitHubVariant.DOTCOM,
|
||||||
SAMPLE_DEFAULT_CLI_VERSION,
|
SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -168,7 +157,7 @@ test("caches semantically versioned bundles using their semantic version number"
|
||||||
util.GitHubVariant.DOTCOM,
|
util.GitHubVariant.DOTCOM,
|
||||||
SAMPLE_DEFAULT_CLI_VERSION,
|
SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -202,7 +191,7 @@ test("downloads an explicitly requested bundle even if a different version is ca
|
||||||
util.GitHubVariant.DOTCOM,
|
util.GitHubVariant.DOTCOM,
|
||||||
SAMPLE_DEFAULT_CLI_VERSION,
|
SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
|
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
|
||||||
|
|
@ -247,7 +236,7 @@ for (const {
|
||||||
util.GitHubVariant.DOTCOM,
|
util.GitHubVariant.DOTCOM,
|
||||||
SAMPLE_DEFAULT_CLI_VERSION,
|
SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
t.assert(toolcache.find("CodeQL", expectedToolcacheVersion));
|
t.assert(toolcache.find("CodeQL", expectedToolcacheVersion));
|
||||||
|
|
@ -286,7 +275,7 @@ for (const toolcacheVersion of [
|
||||||
util.GitHubVariant.DOTCOM,
|
util.GitHubVariant.DOTCOM,
|
||||||
SAMPLE_DEFAULT_CLI_VERSION,
|
SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
t.is(result.toolsVersion, SAMPLE_DEFAULT_CLI_VERSION.cliVersion);
|
t.is(result.toolsVersion, SAMPLE_DEFAULT_CLI_VERSION.cliVersion);
|
||||||
|
|
@ -319,7 +308,7 @@ test(`uses a cached bundle when no tools input is given on GHES`, async (t) => {
|
||||||
tagName: defaults.bundleVersion,
|
tagName: defaults.bundleVersion,
|
||||||
},
|
},
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
t.deepEqual(result.toolsVersion, "0.0.0-20200601");
|
t.deepEqual(result.toolsVersion, "0.0.0-20200601");
|
||||||
|
|
@ -356,7 +345,7 @@ test(`downloads bundle if only an unpinned version is cached on GHES`, async (t)
|
||||||
tagName: defaults.bundleVersion,
|
tagName: defaults.bundleVersion,
|
||||||
},
|
},
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
||||||
|
|
@ -390,7 +379,7 @@ test('downloads bundle if "latest" tools specified but not cached', async (t) =>
|
||||||
util.GitHubVariant.DOTCOM,
|
util.GitHubVariant.DOTCOM,
|
||||||
SAMPLE_DEFAULT_CLI_VERSION,
|
SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
t.deepEqual(result.toolsVersion, defaults.cliVersion);
|
||||||
|
|
@ -426,7 +415,7 @@ test("bundle URL from another repo is cached as 0.0.0-bundleVersion", async (t)
|
||||||
util.GitHubVariant.DOTCOM,
|
util.GitHubVariant.DOTCOM,
|
||||||
SAMPLE_DEFAULT_CLI_VERSION,
|
SAMPLE_DEFAULT_CLI_VERSION,
|
||||||
getRunnerLogger(true),
|
getRunnerLogger(true),
|
||||||
expectedFeatureEnablement,
|
NO_FEATURES,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -395,7 +395,9 @@ export async function setupCodeQL(
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unable to download and extract CodeQL CLI: ${getErrorMessage(e)}`,
|
`Unable to download and extract CodeQL CLI: ${getErrorMessage(e)}${
|
||||||
|
e instanceof Error && e.stack ? `\n\nDetails: ${e.stack}` : ""
|
||||||
|
}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { performance } from "perf_hooks";
|
||||||
import * as toolcache from "@actions/tool-cache";
|
import * as toolcache from "@actions/tool-cache";
|
||||||
import { default as deepEqual } from "fast-deep-equal";
|
import { default as deepEqual } from "fast-deep-equal";
|
||||||
import * as semver from "semver";
|
import * as semver from "semver";
|
||||||
|
import { v4 as uuidV4 } from "uuid";
|
||||||
|
|
||||||
import { isRunningLocalAction } from "./actions-util";
|
import { isRunningLocalAction } from "./actions-util";
|
||||||
import * as api from "./api-client";
|
import * as api from "./api-client";
|
||||||
|
|
@ -13,12 +14,14 @@ import * as defaults from "./defaults.json";
|
||||||
import {
|
import {
|
||||||
CODEQL_VERSION_ZSTD_BUNDLE,
|
CODEQL_VERSION_ZSTD_BUNDLE,
|
||||||
CodeQLDefaultVersionInfo,
|
CodeQLDefaultVersionInfo,
|
||||||
|
Feature,
|
||||||
FeatureEnablement,
|
FeatureEnablement,
|
||||||
} from "./feature-flags";
|
} from "./feature-flags";
|
||||||
import { formatDuration, Logger } from "./logging";
|
import { formatDuration, Logger } from "./logging";
|
||||||
import * as tar from "./tar";
|
import * as tar from "./tar";
|
||||||
import {
|
import {
|
||||||
downloadAndExtract,
|
downloadAndExtract,
|
||||||
|
getToolcacheDirectory,
|
||||||
ToolsDownloadStatusReport,
|
ToolsDownloadStatusReport,
|
||||||
} from "./tools-download";
|
} from "./tools-download";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
|
@ -534,20 +537,29 @@ export const downloadCodeQL = async function (
|
||||||
logger.debug("Downloading CodeQL tools without an authorization token.");
|
logger.debug("Downloading CodeQL tools without an authorization token.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const { extractedBundlePath, statusReport } = await downloadAndExtract(
|
const toolcacheInfo = getToolcacheDestinationInfo(
|
||||||
|
maybeBundleVersion,
|
||||||
|
maybeCliVersion,
|
||||||
|
logger,
|
||||||
|
);
|
||||||
|
const extractToToolcache =
|
||||||
|
!!toolcacheInfo && !!(await features.getValue(Feature.ExtractToToolcache));
|
||||||
|
|
||||||
|
const extractedBundlePath = extractToToolcache
|
||||||
|
? toolcacheInfo.path
|
||||||
|
: getTempExtractionDir(tempDir);
|
||||||
|
|
||||||
|
const statusReport = await downloadAndExtract(
|
||||||
codeqlURL,
|
codeqlURL,
|
||||||
|
extractedBundlePath,
|
||||||
authorization,
|
authorization,
|
||||||
{ "User-Agent": "CodeQL Action", ...headers },
|
{ "User-Agent": "CodeQL Action", ...headers },
|
||||||
tarVersion,
|
tarVersion,
|
||||||
tempDir,
|
|
||||||
features,
|
features,
|
||||||
logger,
|
logger,
|
||||||
);
|
);
|
||||||
|
|
||||||
const bundleVersion =
|
if (!toolcacheInfo) {
|
||||||
maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
|
|
||||||
|
|
||||||
if (bundleVersion === undefined) {
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Could not cache CodeQL tools because we could not determine the bundle version from the " +
|
"Could not cache CodeQL tools because we could not determine the bundle version from the " +
|
||||||
`URL ${codeqlURL}.`,
|
`URL ${codeqlURL}.`,
|
||||||
|
|
@ -560,16 +572,11 @@ export const downloadCodeQL = async function (
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Caching CodeQL bundle.");
|
logger.debug("Caching CodeQL bundle.");
|
||||||
const toolcacheVersion = getCanonicalToolcacheVersion(
|
|
||||||
maybeCliVersion,
|
|
||||||
bundleVersion,
|
|
||||||
logger,
|
|
||||||
);
|
|
||||||
const toolcacheStart = performance.now();
|
const toolcacheStart = performance.now();
|
||||||
const toolcachedBundlePath = await toolcache.cacheDir(
|
const toolcachedBundlePath = await toolcache.cacheDir(
|
||||||
extractedBundlePath,
|
extractedBundlePath,
|
||||||
"CodeQL",
|
"CodeQL",
|
||||||
toolcacheVersion,
|
toolcacheInfo.version,
|
||||||
);
|
);
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
|
|
@ -590,10 +597,31 @@ export const downloadCodeQL = async function (
|
||||||
return {
|
return {
|
||||||
codeqlFolder: toolcachedBundlePath,
|
codeqlFolder: toolcachedBundlePath,
|
||||||
statusReport,
|
statusReport,
|
||||||
toolsVersion: maybeCliVersion ?? toolcacheVersion,
|
toolsVersion: maybeCliVersion ?? toolcacheInfo.version,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getToolcacheDestinationInfo(
|
||||||
|
maybeBundleVersion: string | undefined,
|
||||||
|
maybeCliVersion: string | undefined,
|
||||||
|
logger: Logger,
|
||||||
|
): { path: string; version: string } | undefined {
|
||||||
|
if (maybeBundleVersion) {
|
||||||
|
const version = getCanonicalToolcacheVersion(
|
||||||
|
maybeCliVersion,
|
||||||
|
maybeBundleVersion,
|
||||||
|
logger,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
path: getToolcacheDirectory(version),
|
||||||
|
version,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export function getCodeQLURLVersion(url: string): string {
|
export function getCodeQLURLVersion(url: string): string {
|
||||||
const match = url.match(/\/codeql-bundle-(.*)\//);
|
const match = url.match(/\/codeql-bundle-(.*)\//);
|
||||||
if (match === null || match.length < 2) {
|
if (match === null || match.length < 2) {
|
||||||
|
|
@ -617,7 +645,7 @@ function getCanonicalToolcacheVersion(
|
||||||
cliVersion: string | undefined,
|
cliVersion: string | undefined,
|
||||||
bundleVersion: string,
|
bundleVersion: string,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
) {
|
): string {
|
||||||
// If the CLI version is a pre-release or contains build metadata, then cache the
|
// If the CLI version is a pre-release or contains build metadata, then cache the
|
||||||
// bundle as `0.0.0-<bundleVersion>` to avoid the bundle being interpreted as containing a stable
|
// bundle as `0.0.0-<bundleVersion>` to avoid the bundle being interpreted as containing a stable
|
||||||
// CLI release. In principle, it should be enough to just check that the CLI version isn't a
|
// CLI release. In principle, it should be enough to just check that the CLI version isn't a
|
||||||
|
|
@ -680,6 +708,7 @@ export async function setupCodeQLBundle(
|
||||||
);
|
);
|
||||||
codeqlFolder = await tar.extract(
|
codeqlFolder = await tar.extract(
|
||||||
source.codeqlTarPath,
|
source.codeqlTarPath,
|
||||||
|
getTempExtractionDir(tempDir),
|
||||||
compressionMethod,
|
compressionMethod,
|
||||||
zstdAvailability.version,
|
zstdAvailability.version,
|
||||||
logger,
|
logger,
|
||||||
|
|
@ -732,3 +761,7 @@ async function useZstdBundle(
|
||||||
semver.gte(cliVersion, CODEQL_VERSION_ZSTD_BUNDLE)
|
semver.gte(cliVersion, CODEQL_VERSION_ZSTD_BUNDLE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTempExtractionDir(tempDir: string) {
|
||||||
|
return path.join(tempDir, uuidV4());
|
||||||
|
}
|
||||||
|
|
|
||||||
17
src/tar.ts
17
src/tar.ts
|
|
@ -1,14 +1,12 @@
|
||||||
import { spawn } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import path from "path";
|
|
||||||
import * as stream from "stream";
|
import * as stream from "stream";
|
||||||
|
|
||||||
import { ToolRunner } from "@actions/exec/lib/toolrunner";
|
import { ToolRunner } from "@actions/exec/lib/toolrunner";
|
||||||
import * as toolcache from "@actions/tool-cache";
|
import * as toolcache from "@actions/tool-cache";
|
||||||
import { safeWhich } from "@chrisgavin/safe-which";
|
import { safeWhich } from "@chrisgavin/safe-which";
|
||||||
import { v4 as uuidV4 } from "uuid";
|
|
||||||
|
|
||||||
import { CommandInvocationError, getTemporaryDirectory } from "./actions-util";
|
import { CommandInvocationError } from "./actions-util";
|
||||||
import { Logger } from "./logging";
|
import { Logger } from "./logging";
|
||||||
import { assertNever, cleanUpGlob, isBinaryAccessible } from "./util";
|
import { assertNever, cleanUpGlob, isBinaryAccessible } from "./util";
|
||||||
|
|
||||||
|
|
@ -96,22 +94,25 @@ export type CompressionMethod = "gzip" | "zstd";
|
||||||
|
|
||||||
export async function extract(
|
export async function extract(
|
||||||
tarPath: string,
|
tarPath: string,
|
||||||
|
dest: string,
|
||||||
compressionMethod: CompressionMethod,
|
compressionMethod: CompressionMethod,
|
||||||
tarVersion: TarVersion | undefined,
|
tarVersion: TarVersion | undefined,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
// Ensure destination exists
|
||||||
|
fs.mkdirSync(dest, { recursive: true });
|
||||||
|
|
||||||
switch (compressionMethod) {
|
switch (compressionMethod) {
|
||||||
case "gzip":
|
case "gzip":
|
||||||
// Defensively continue to call the toolcache API as requesting a gzipped
|
// Defensively continue to call the toolcache API as requesting a gzipped
|
||||||
// bundle may be a fallback option.
|
// bundle may be a fallback option.
|
||||||
return await toolcache.extractTar(tarPath);
|
return await toolcache.extractTar(tarPath, dest);
|
||||||
case "zstd": {
|
case "zstd": {
|
||||||
if (!tarVersion) {
|
if (!tarVersion) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Could not determine tar version, which is required to extract a Zstandard archive.",
|
"Could not determine tar version, which is required to extract a Zstandard archive.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const dest = await createExtractFolder();
|
|
||||||
await extractTarZst(tarPath, dest, tarVersion, logger);
|
await extractTarZst(tarPath, dest, tarVersion, logger);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
@ -192,12 +193,6 @@ export async function extractTarZst(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createExtractFolder(): Promise<string> {
|
|
||||||
const dest = path.join(getTemporaryDirectory(), uuidV4());
|
|
||||||
fs.mkdirSync(dest, { recursive: true });
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function inferCompressionMethod(tarPath: string): CompressionMethod {
|
export function inferCompressionMethod(tarPath: string): CompressionMethod {
|
||||||
if (tarPath.endsWith(".tar.gz")) {
|
if (tarPath.endsWith(".tar.gz")) {
|
||||||
return "gzip";
|
return "gzip";
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,27 @@
|
||||||
import { IncomingMessage, OutgoingHttpHeaders, RequestOptions } from "http";
|
import { IncomingMessage, OutgoingHttpHeaders, RequestOptions } from "http";
|
||||||
|
import * as os from "os";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { performance } from "perf_hooks";
|
import { performance } from "perf_hooks";
|
||||||
|
|
||||||
import * as toolcache from "@actions/tool-cache";
|
import * as toolcache from "@actions/tool-cache";
|
||||||
import { https } from "follow-redirects";
|
import { https } from "follow-redirects";
|
||||||
import { v4 as uuidV4 } from "uuid";
|
import * as semver from "semver";
|
||||||
|
|
||||||
import { Feature, FeatureEnablement } from "./feature-flags";
|
import { Feature, FeatureEnablement } from "./feature-flags";
|
||||||
import { formatDuration, Logger } from "./logging";
|
import { formatDuration, Logger } from "./logging";
|
||||||
import * as tar from "./tar";
|
import * as tar from "./tar";
|
||||||
import { cleanUpGlob } from "./util";
|
import { cleanUpGlob, getRequiredEnvParam } from "./util";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* High watermark to use when streaming the download and extraction of the CodeQL tools.
|
* High watermark to use when streaming the download and extraction of the CodeQL tools.
|
||||||
*/
|
*/
|
||||||
export const STREAMING_HIGH_WATERMARK_BYTES = 4 * 1024 * 1024; // 4 MiB
|
export const STREAMING_HIGH_WATERMARK_BYTES = 4 * 1024 * 1024; // 4 MiB
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the tool cache directory for the CodeQL tools.
|
||||||
|
*/
|
||||||
|
const TOOLCACHE_TOOL_NAME = "CodeQL";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timing information for the download and extraction of the CodeQL tools when
|
* Timing information for the download and extraction of the CodeQL tools when
|
||||||
* we fully download the bundle before extracting.
|
* we fully download the bundle before extracting.
|
||||||
|
|
@ -73,16 +79,13 @@ export type ToolsDownloadStatusReport = {
|
||||||
|
|
||||||
export async function downloadAndExtract(
|
export async function downloadAndExtract(
|
||||||
codeqlURL: string,
|
codeqlURL: string,
|
||||||
|
dest: string,
|
||||||
authorization: string | undefined,
|
authorization: string | undefined,
|
||||||
headers: OutgoingHttpHeaders,
|
headers: OutgoingHttpHeaders,
|
||||||
tarVersion: tar.TarVersion | undefined,
|
tarVersion: tar.TarVersion | undefined,
|
||||||
tempDir: string,
|
|
||||||
features: FeatureEnablement,
|
features: FeatureEnablement,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
): Promise<{
|
): Promise<ToolsDownloadStatusReport> {
|
||||||
extractedBundlePath: string;
|
|
||||||
statusReport: ToolsDownloadStatusReport;
|
|
||||||
}> {
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`Downloading CodeQL tools from ${codeqlURL} . This may take a while.`,
|
`Downloading CodeQL tools from ${codeqlURL} . This may take a while.`,
|
||||||
);
|
);
|
||||||
|
|
@ -99,10 +102,9 @@ export async function downloadAndExtract(
|
||||||
logger.info(`Streaming the extraction of the CodeQL bundle.`);
|
logger.info(`Streaming the extraction of the CodeQL bundle.`);
|
||||||
|
|
||||||
const toolsInstallStart = performance.now();
|
const toolsInstallStart = performance.now();
|
||||||
const extractedBundlePath = await tar.createExtractFolder();
|
|
||||||
await downloadAndExtractZstdWithStreaming(
|
await downloadAndExtractZstdWithStreaming(
|
||||||
codeqlURL,
|
codeqlURL,
|
||||||
extractedBundlePath,
|
dest,
|
||||||
authorization,
|
authorization,
|
||||||
headers,
|
headers,
|
||||||
tarVersion!,
|
tarVersion!,
|
||||||
|
|
@ -113,27 +115,22 @@ export async function downloadAndExtract(
|
||||||
performance.now() - toolsInstallStart,
|
performance.now() - toolsInstallStart,
|
||||||
);
|
);
|
||||||
logger.info(
|
logger.info(
|
||||||
`Finished downloading and extracting CodeQL bundle to ${extractedBundlePath} (${formatDuration(
|
`Finished downloading and extracting CodeQL bundle to ${dest} (${formatDuration(
|
||||||
combinedDurationMs,
|
combinedDurationMs,
|
||||||
)}).`,
|
)}).`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
extractedBundlePath,
|
compressionMethod,
|
||||||
statusReport: {
|
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||||
compressionMethod,
|
...makeStreamedToolsDownloadDurations(combinedDurationMs),
|
||||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
|
||||||
...makeStreamedToolsDownloadDurations(combinedDurationMs),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const dest = path.join(tempDir, uuidV4());
|
|
||||||
|
|
||||||
const toolsDownloadStart = performance.now();
|
const toolsDownloadStart = performance.now();
|
||||||
const archivedBundlePath = await toolcache.downloadTool(
|
const archivedBundlePath = await toolcache.downloadTool(
|
||||||
codeqlURL,
|
codeqlURL,
|
||||||
dest,
|
undefined,
|
||||||
authorization,
|
authorization,
|
||||||
headers,
|
headers,
|
||||||
);
|
);
|
||||||
|
|
@ -145,21 +142,21 @@ export async function downloadAndExtract(
|
||||||
)}).`,
|
)}).`,
|
||||||
);
|
);
|
||||||
|
|
||||||
let extractedBundlePath: string;
|
|
||||||
let extractionDurationMs: number;
|
let extractionDurationMs: number;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Extracting CodeQL bundle.");
|
logger.info("Extracting CodeQL bundle.");
|
||||||
const extractionStart = performance.now();
|
const extractionStart = performance.now();
|
||||||
extractedBundlePath = await tar.extract(
|
await tar.extract(
|
||||||
archivedBundlePath,
|
archivedBundlePath,
|
||||||
|
dest,
|
||||||
compressionMethod,
|
compressionMethod,
|
||||||
tarVersion,
|
tarVersion,
|
||||||
logger,
|
logger,
|
||||||
);
|
);
|
||||||
extractionDurationMs = Math.round(performance.now() - extractionStart);
|
extractionDurationMs = Math.round(performance.now() - extractionStart);
|
||||||
logger.info(
|
logger.info(
|
||||||
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${formatDuration(
|
`Finished extracting CodeQL bundle to ${dest} (${formatDuration(
|
||||||
extractionDurationMs,
|
extractionDurationMs,
|
||||||
)}).`,
|
)}).`,
|
||||||
);
|
);
|
||||||
|
|
@ -168,15 +165,12 @@ export async function downloadAndExtract(
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
extractedBundlePath,
|
compressionMethod,
|
||||||
statusReport: {
|
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||||
compressionMethod,
|
...makeDownloadFirstToolsDownloadDurations(
|
||||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
downloadDurationMs,
|
||||||
...makeDownloadFirstToolsDownloadDurations(
|
extractionDurationMs,
|
||||||
downloadDurationMs,
|
),
|
||||||
extractionDurationMs,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,6 +207,16 @@ async function downloadAndExtractZstdWithStreaming(
|
||||||
await tar.extractTarZst(response, dest, tarVersion, logger);
|
await tar.extractTarZst(response, dest, tarVersion, logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets the path to the toolcache directory for the specified version of the CodeQL tools. */
|
||||||
|
export function getToolcacheDirectory(version: string): string {
|
||||||
|
return path.join(
|
||||||
|
getRequiredEnvParam("RUNNER_TOOL_CACHE"),
|
||||||
|
TOOLCACHE_TOOL_NAME,
|
||||||
|
semver.clean(version) || version,
|
||||||
|
os.arch() || "",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function sanitizeUrlForStatusReport(url: string): string {
|
function sanitizeUrlForStatusReport(url: string): string {
|
||||||
return ["github/codeql-action", "dsp-testing/codeql-cli-nightlies"].some(
|
return ["github/codeql-action", "dsp-testing/codeql-cli-nightlies"].some(
|
||||||
(repo) => url.startsWith(`https://github.com/${repo}/releases/download/`),
|
(repo) => url.startsWith(`https://github.com/${repo}/releases/download/`),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue