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) {
|
||||
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 defaults = __importStar(require("./defaults.json"));
|
||||
const doc_url_1 = require("./doc-url");
|
||||
const feature_flags_test_1 = require("./feature-flags.test");
|
||||
const languages_1 = require("./languages");
|
||||
const logging_1 = require("./logging");
|
||||
const setup_codeql_1 = require("./setup-codeql");
|
||||
|
|
@ -51,12 +50,7 @@ const util = __importStar(require("./util"));
|
|||
const util_1 = require("./util");
|
||||
(0, testing_utils_1.setupTests)(ava_1.default);
|
||||
let stubConfig;
|
||||
// TODO: Remove when when we no longer need to pass in features (https://github.com/github/codeql-action/issues/2600)
|
||||
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];
|
||||
};
|
||||
const NO_FEATURES = (0, testing_utils_1.createFeatures)([]);
|
||||
ava_1.default.beforeEach(() => {
|
||||
(0, util_1.initializeEnvironment)("1.2.3");
|
||||
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 });
|
||||
await codeql.setupCodeQL(cliVersion !== undefined ? undefined : url, apiDetails, tmpDir, util.GitHubVariant.GHES, cliVersion !== undefined
|
||||
? { 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, }) {
|
||||
return (0, nock_1.default)(apiDetails.apiURL)
|
||||
|
|
@ -88,11 +82,8 @@ function mockApiDetails(apiDetails) {
|
|||
.stub(actionsUtil, "getRequiredInput")
|
||||
.withArgs("token")
|
||||
.returns(apiDetails.auth);
|
||||
const requiredEnvParamStub = sinon.stub(util, "getRequiredEnvParam");
|
||||
requiredEnvParamStub.withArgs("GITHUB_SERVER_URL").returns(apiDetails.url);
|
||||
requiredEnvParamStub
|
||||
.withArgs("GITHUB_API_URL")
|
||||
.returns(apiDetails.apiURL || "");
|
||||
process.env["GITHUB_SERVER_URL"] = apiDetails.url;
|
||||
process.env["GITHUB_API_URL"] = apiDetails.apiURL || "";
|
||||
}
|
||||
(0, ava_1.default)("downloads and caches explicitly requested bundles that aren't in the toolcache", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
|
|
@ -104,7 +95,7 @@ function mockApiDetails(apiDetails) {
|
|||
tagName: `codeql-bundle-${version}`,
|
||||
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.is(result.toolsVersion, `0.0.0-${version}`);
|
||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||
|
|
@ -119,7 +110,7 @@ function mockApiDetails(apiDetails) {
|
|||
tagName: `codeql-bundle-v2.15.0`,
|
||||
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.assert(toolcache.find("CodeQL", `2.15.0`));
|
||||
t.is(result.toolsVersion, `2.15.0`);
|
||||
|
|
@ -140,7 +131,7 @@ function mockApiDetails(apiDetails) {
|
|||
const url = (0, testing_utils_1.mockBundleDownloadApi)({
|
||||
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.deepEqual(result.toolsVersion, "0.0.0-20200610");
|
||||
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)({
|
||||
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.deepEqual(result.toolsVersion, expectedToolcacheVersion);
|
||||
t.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||
|
|
@ -191,7 +182,7 @@ for (const toolcacheVersion of [
|
|||
.withArgs("CodeQL", toolcacheVersion)
|
||||
.returns("path/to/cached/codeql");
|
||||
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.toolsSource, setup_codeql_1.ToolsSource.Toolcache);
|
||||
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, {
|
||||
cliVersion: defaults.cliVersion,
|
||||
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.is(result.toolsSource, setup_codeql_1.ToolsSource.Toolcache);
|
||||
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, {
|
||||
cliVersion: defaults.cliVersion,
|
||||
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.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||
if (result.toolsDownloadStatusReport) {
|
||||
|
|
@ -256,7 +247,7 @@ for (const toolcacheVersion of [
|
|||
(0, testing_utils_1.mockBundleDownloadApi)({
|
||||
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.is(result.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||
if (result.toolsDownloadStatusReport) {
|
||||
|
|
@ -280,7 +271,7 @@ for (const toolcacheVersion of [
|
|||
platformSpecific: false,
|
||||
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.toolsSource, setup_codeql_1.ToolsSource.Download);
|
||||
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 fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
||||
const semver = __importStar(require("semver"));
|
||||
const uuid_1 = require("uuid");
|
||||
const actions_util_1 = require("./actions-util");
|
||||
const api = __importStar(require("./api-client"));
|
||||
const defaults = __importStar(require("./defaults.json"));
|
||||
|
|
@ -401,9 +402,13 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
|
|||
else {
|
||||
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 bundleVersion = maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
|
||||
if (bundleVersion === undefined) {
|
||||
const toolcacheInfo = getToolcacheDestinationInfo(maybeBundleVersion, maybeCliVersion, logger);
|
||||
const extractToToolcache = !!toolcacheInfo && !!(await features.getValue(feature_flags_1.Feature.ExtractToToolcache));
|
||||
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 " +
|
||||
`URL ${codeqlURL}.`);
|
||||
return {
|
||||
|
|
@ -413,9 +418,8 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
|
|||
};
|
||||
}
|
||||
logger.debug("Caching CodeQL bundle.");
|
||||
const toolcacheVersion = getCanonicalToolcacheVersion(maybeCliVersion, bundleVersion, logger);
|
||||
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)}).`);
|
||||
// Defensive check: we expect `cacheDir` to copy the bundle to a new location.
|
||||
if (toolcachedBundlePath !== extractedBundlePath) {
|
||||
|
|
@ -424,10 +428,20 @@ const downloadCodeQL = async function (codeqlURL, maybeBundleVersion, maybeCliVe
|
|||
return {
|
||||
codeqlFolder: toolcachedBundlePath,
|
||||
statusReport,
|
||||
toolsVersion: maybeCliVersion ?? toolcacheVersion,
|
||||
toolsVersion: maybeCliVersion ?? toolcacheInfo.version,
|
||||
};
|
||||
};
|
||||
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) {
|
||||
const match = url.match(/\/codeql-bundle-(.*)\//);
|
||||
if (match === null || match.length < 2) {
|
||||
|
|
@ -475,7 +489,7 @@ async function setupCodeQLBundle(toolsInput, apiDetails, tempDir, variant, featu
|
|||
switch (source.sourceType) {
|
||||
case "local": {
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
|
@ -510,4 +524,7 @@ async function useZstdBundle(cliVersion, tarSupportsZstd) {
|
|||
tarSupportsZstd &&
|
||||
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
|
||||
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);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isZstdAvailable = isZstdAvailable;
|
||||
exports.extract = extract;
|
||||
exports.extractTarZst = extractTarZst;
|
||||
exports.createExtractFolder = createExtractFolder;
|
||||
exports.inferCompressionMethod = inferCompressionMethod;
|
||||
const child_process_1 = require("child_process");
|
||||
const fs = __importStar(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const stream = __importStar(require("stream"));
|
||||
const toolrunner_1 = require("@actions/exec/lib/toolrunner");
|
||||
const toolcache = __importStar(require("@actions/tool-cache"));
|
||||
const safe_which_1 = require("@chrisgavin/safe-which");
|
||||
const uuid_1 = require("uuid");
|
||||
const actions_util_1 = require("./actions-util");
|
||||
const util_1 = require("./util");
|
||||
const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
|
||||
|
|
@ -104,17 +98,18 @@ async function isZstdAvailable(logger) {
|
|||
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) {
|
||||
case "gzip":
|
||||
// Defensively continue to call the toolcache API as requesting a gzipped
|
||||
// bundle may be a fallback option.
|
||||
return await toolcache.extractTar(tarPath);
|
||||
return await toolcache.extractTar(tarPath, dest);
|
||||
case "zstd": {
|
||||
if (!tarVersion) {
|
||||
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);
|
||||
return dest;
|
||||
}
|
||||
|
|
@ -169,11 +164,6 @@ async function extractTarZst(tar, dest, tarVersion, logger) {
|
|||
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) {
|
||||
if (tarPath.endsWith(".tar.gz")) {
|
||||
return "gzip";
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"tar.js","sourceRoot":"","sources":["../src/tar.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,0CA+BC;AAID,0BAsBC;AAQD,sCAkEC;AAED,kDAIC;AAED,wDAKC;AA7MD,iDAAsC;AACtC,uCAAyB;AACzB,gDAAwB;AACxB,+CAAiC;AAEjC,6DAA0D;AAC1D,+DAAiD;AACjD,uDAAmD;AACnD,+BAAoC;AAEpC,iDAA+E;AAE/E,iCAAsE;AAEtE,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAC7C,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAO5C,KAAK,UAAU,aAAa;IAC1B,MAAM,GAAG,GAAG,MAAM,IAAA,sBAAS,EAAC,KAAK,CAAC,CAAC;IACnC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,MAAM,QAAQ,GAAG,MAAM,IAAI,uBAAU,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE;QACxD,SAAS,EAAE;YACT,MAAM,EAAE,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IAAI,KAAK,CAAC,EAAE,CAAC;oBACf,MAAM,CACJ,IAAI,qCAAsB,CACxB,KAAK,EACL,IAAI,EACJ,IAAI,IAAI,SAAS,EACjB,MAAM,EACN,MAAM,CACP,CACF,CAAC;gBACJ,CAAC;gBACD,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAA,kBAAW,EAAC,IAAI,EAAE,kCAAkC,EAAE,MAAM,CAAC,CAAC;QACpE,MAAM,CAAC,CAAC;IACV,CAAC;AACH,CAAC;AAED,SAAgB,sBAAsB,CAAC,OAAe;IACpD,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAChC,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
||||
45
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 });
|
||||
exports.STREAMING_HIGH_WATERMARK_BYTES = void 0;
|
||||
exports.downloadAndExtract = downloadAndExtract;
|
||||
exports.getToolcacheDirectory = getToolcacheDirectory;
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
const perf_hooks_1 = require("perf_hooks");
|
||||
const toolcache = __importStar(require("@actions/tool-cache"));
|
||||
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 logging_1 = require("./logging");
|
||||
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.
|
||||
*/
|
||||
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) {
|
||||
return {
|
||||
combinedDurationMs: downloadDurationMs + extractionDurationMs,
|
||||
|
|
@ -54,7 +60,7 @@ function makeStreamedToolsDownloadDurations(combinedDurationMs) {
|
|||
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.`);
|
||||
const compressionMethod = tar.inferCompressionMethod(codeqlURL);
|
||||
// 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") {
|
||||
logger.info(`Streaming the extraction of the CodeQL bundle.`);
|
||||
const toolsInstallStart = perf_hooks_1.performance.now();
|
||||
const extractedBundlePath = await tar.createExtractFolder();
|
||||
await downloadAndExtractZstdWithStreaming(codeqlURL, extractedBundlePath, authorization, headers, tarVersion, logger);
|
||||
await downloadAndExtractZstdWithStreaming(codeqlURL, dest, authorization, headers, tarVersion, logger);
|
||||
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 {
|
||||
extractedBundlePath,
|
||||
statusReport: {
|
||||
compressionMethod,
|
||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||
...makeStreamedToolsDownloadDurations(combinedDurationMs),
|
||||
},
|
||||
compressionMethod,
|
||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||
...makeStreamedToolsDownloadDurations(combinedDurationMs),
|
||||
};
|
||||
}
|
||||
const dest = path.join(tempDir, (0, uuid_1.v4)());
|
||||
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);
|
||||
logger.info(`Finished downloading CodeQL bundle to ${archivedBundlePath} (${(0, logging_1.formatDuration)(downloadDurationMs)}).`);
|
||||
let extractedBundlePath;
|
||||
let extractionDurationMs;
|
||||
try {
|
||||
logger.info("Extracting CodeQL bundle.");
|
||||
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);
|
||||
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 {
|
||||
await (0, util_1.cleanUpGlob)(archivedBundlePath, "CodeQL bundle archive", logger);
|
||||
}
|
||||
return {
|
||||
extractedBundlePath,
|
||||
statusReport: {
|
||||
compressionMethod,
|
||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||
...makeDownloadFirstToolsDownloadDurations(downloadDurationMs, extractionDurationMs),
|
||||
},
|
||||
compressionMethod,
|
||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||
...makeDownloadFirstToolsDownloadDurations(downloadDurationMs, extractionDurationMs),
|
||||
};
|
||||
}
|
||||
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);
|
||||
}
|
||||
/** 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) {
|
||||
return ["github/codeql-action", "dsp-testing/codeql-cli-nightlies"].some((repo) => url.startsWith(`https://github.com/${repo}/releases/download/`))
|
||||
? 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;AA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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 * as defaults from "./defaults.json";
|
||||
import { DocUrl } from "./doc-url";
|
||||
import { Feature, FeatureEnablement } from "./feature-flags";
|
||||
import { initializeFeatures } from "./feature-flags.test";
|
||||
import { FeatureEnablement } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { ToolsSource } from "./setup-codeql";
|
||||
|
|
@ -41,14 +40,7 @@ setupTests(test);
|
|||
|
||||
let stubConfig: Config;
|
||||
|
||||
// TODO: Remove when when we no longer need to pass in features (https://github.com/github/codeql-action/issues/2600)
|
||||
const expectedFeatureEnablement: FeatureEnablement = initializeFeatures(
|
||||
true,
|
||||
) as FeatureEnablement;
|
||||
expectedFeatureEnablement.getValue = function (feature: Feature) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return expectedFeatureEnablement[feature];
|
||||
};
|
||||
const NO_FEATURES: FeatureEnablement = createFeatures([]);
|
||||
|
||||
test.beforeEach(() => {
|
||||
initializeEnvironment("1.2.3");
|
||||
|
|
@ -81,7 +73,7 @@ async function installIntoToolcache({
|
|||
? { cliVersion, tagName }
|
||||
: SAMPLE_DEFAULT_CLI_VERSION,
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
|
@ -114,11 +106,8 @@ function mockApiDetails(apiDetails: GitHubApiDetails) {
|
|||
.stub(actionsUtil, "getRequiredInput")
|
||||
.withArgs("token")
|
||||
.returns(apiDetails.auth);
|
||||
const requiredEnvParamStub = sinon.stub(util, "getRequiredEnvParam");
|
||||
requiredEnvParamStub.withArgs("GITHUB_SERVER_URL").returns(apiDetails.url);
|
||||
requiredEnvParamStub
|
||||
.withArgs("GITHUB_API_URL")
|
||||
.returns(apiDetails.apiURL || "");
|
||||
process.env["GITHUB_SERVER_URL"] = apiDetails.url;
|
||||
process.env["GITHUB_API_URL"] = apiDetails.apiURL || "";
|
||||
}
|
||||
|
||||
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,
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
|
||||
|
|
@ -168,7 +157,7 @@ test("caches semantically versioned bundles using their semantic version number"
|
|||
util.GitHubVariant.DOTCOM,
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
|
||||
|
|
@ -202,7 +191,7 @@ test("downloads an explicitly requested bundle even if a different version is ca
|
|||
util.GitHubVariant.DOTCOM,
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
t.assert(toolcache.find("CodeQL", "0.0.0-20200610"));
|
||||
|
|
@ -247,7 +236,7 @@ for (const {
|
|||
util.GitHubVariant.DOTCOM,
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
t.assert(toolcache.find("CodeQL", expectedToolcacheVersion));
|
||||
|
|
@ -286,7 +275,7 @@ for (const toolcacheVersion of [
|
|||
util.GitHubVariant.DOTCOM,
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
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,
|
||||
},
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
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,
|
||||
},
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
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,
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
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,
|
||||
SAMPLE_DEFAULT_CLI_VERSION,
|
||||
getRunnerLogger(true),
|
||||
expectedFeatureEnablement,
|
||||
NO_FEATURES,
|
||||
false,
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -395,7 +395,9 @@ export async function setupCodeQL(
|
|||
};
|
||||
} catch (e) {
|
||||
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 { default as deepEqual } from "fast-deep-equal";
|
||||
import * as semver from "semver";
|
||||
import { v4 as uuidV4 } from "uuid";
|
||||
|
||||
import { isRunningLocalAction } from "./actions-util";
|
||||
import * as api from "./api-client";
|
||||
|
|
@ -13,12 +14,14 @@ import * as defaults from "./defaults.json";
|
|||
import {
|
||||
CODEQL_VERSION_ZSTD_BUNDLE,
|
||||
CodeQLDefaultVersionInfo,
|
||||
Feature,
|
||||
FeatureEnablement,
|
||||
} from "./feature-flags";
|
||||
import { formatDuration, Logger } from "./logging";
|
||||
import * as tar from "./tar";
|
||||
import {
|
||||
downloadAndExtract,
|
||||
getToolcacheDirectory,
|
||||
ToolsDownloadStatusReport,
|
||||
} from "./tools-download";
|
||||
import * as util from "./util";
|
||||
|
|
@ -534,20 +537,29 @@ export const downloadCodeQL = async function (
|
|||
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,
|
||||
extractedBundlePath,
|
||||
authorization,
|
||||
{ "User-Agent": "CodeQL Action", ...headers },
|
||||
tarVersion,
|
||||
tempDir,
|
||||
features,
|
||||
logger,
|
||||
);
|
||||
|
||||
const bundleVersion =
|
||||
maybeBundleVersion ?? tryGetBundleVersionFromUrl(codeqlURL, logger);
|
||||
|
||||
if (bundleVersion === undefined) {
|
||||
if (!toolcacheInfo) {
|
||||
logger.debug(
|
||||
"Could not cache CodeQL tools because we could not determine the bundle version from the " +
|
||||
`URL ${codeqlURL}.`,
|
||||
|
|
@ -560,16 +572,11 @@ export const downloadCodeQL = async function (
|
|||
}
|
||||
|
||||
logger.debug("Caching CodeQL bundle.");
|
||||
const toolcacheVersion = getCanonicalToolcacheVersion(
|
||||
maybeCliVersion,
|
||||
bundleVersion,
|
||||
logger,
|
||||
);
|
||||
const toolcacheStart = performance.now();
|
||||
const toolcachedBundlePath = await toolcache.cacheDir(
|
||||
extractedBundlePath,
|
||||
"CodeQL",
|
||||
toolcacheVersion,
|
||||
toolcacheInfo.version,
|
||||
);
|
||||
|
||||
logger.info(
|
||||
|
|
@ -590,10 +597,31 @@ export const downloadCodeQL = async function (
|
|||
return {
|
||||
codeqlFolder: toolcachedBundlePath,
|
||||
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 {
|
||||
const match = url.match(/\/codeql-bundle-(.*)\//);
|
||||
if (match === null || match.length < 2) {
|
||||
|
|
@ -617,7 +645,7 @@ function getCanonicalToolcacheVersion(
|
|||
cliVersion: string | undefined,
|
||||
bundleVersion: string,
|
||||
logger: Logger,
|
||||
) {
|
||||
): string {
|
||||
// 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
|
||||
// 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(
|
||||
source.codeqlTarPath,
|
||||
getTempExtractionDir(tempDir),
|
||||
compressionMethod,
|
||||
zstdAvailability.version,
|
||||
logger,
|
||||
|
|
@ -732,3 +761,7 @@ async function useZstdBundle(
|
|||
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 * as fs from "fs";
|
||||
import path from "path";
|
||||
import * as stream from "stream";
|
||||
|
||||
import { ToolRunner } from "@actions/exec/lib/toolrunner";
|
||||
import * as toolcache from "@actions/tool-cache";
|
||||
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 { assertNever, cleanUpGlob, isBinaryAccessible } from "./util";
|
||||
|
||||
|
|
@ -96,22 +94,25 @@ export type CompressionMethod = "gzip" | "zstd";
|
|||
|
||||
export async function extract(
|
||||
tarPath: string,
|
||||
dest: string,
|
||||
compressionMethod: CompressionMethod,
|
||||
tarVersion: TarVersion | undefined,
|
||||
logger: Logger,
|
||||
): Promise<string> {
|
||||
// Ensure destination exists
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
|
||||
switch (compressionMethod) {
|
||||
case "gzip":
|
||||
// Defensively continue to call the toolcache API as requesting a gzipped
|
||||
// bundle may be a fallback option.
|
||||
return await toolcache.extractTar(tarPath);
|
||||
return await toolcache.extractTar(tarPath, dest);
|
||||
case "zstd": {
|
||||
if (!tarVersion) {
|
||||
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);
|
||||
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 {
|
||||
if (tarPath.endsWith(".tar.gz")) {
|
||||
return "gzip";
|
||||
|
|
|
|||
|
|
@ -1,21 +1,27 @@
|
|||
import { IncomingMessage, OutgoingHttpHeaders, RequestOptions } from "http";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import { performance } from "perf_hooks";
|
||||
|
||||
import * as toolcache from "@actions/tool-cache";
|
||||
import { https } from "follow-redirects";
|
||||
import { v4 as uuidV4 } from "uuid";
|
||||
import * as semver from "semver";
|
||||
|
||||
import { Feature, FeatureEnablement } from "./feature-flags";
|
||||
import { formatDuration, Logger } from "./logging";
|
||||
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.
|
||||
*/
|
||||
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
|
||||
* we fully download the bundle before extracting.
|
||||
|
|
@ -73,16 +79,13 @@ export type ToolsDownloadStatusReport = {
|
|||
|
||||
export async function downloadAndExtract(
|
||||
codeqlURL: string,
|
||||
dest: string,
|
||||
authorization: string | undefined,
|
||||
headers: OutgoingHttpHeaders,
|
||||
tarVersion: tar.TarVersion | undefined,
|
||||
tempDir: string,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
): Promise<{
|
||||
extractedBundlePath: string;
|
||||
statusReport: ToolsDownloadStatusReport;
|
||||
}> {
|
||||
): Promise<ToolsDownloadStatusReport> {
|
||||
logger.info(
|
||||
`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.`);
|
||||
|
||||
const toolsInstallStart = performance.now();
|
||||
const extractedBundlePath = await tar.createExtractFolder();
|
||||
await downloadAndExtractZstdWithStreaming(
|
||||
codeqlURL,
|
||||
extractedBundlePath,
|
||||
dest,
|
||||
authorization,
|
||||
headers,
|
||||
tarVersion!,
|
||||
|
|
@ -113,27 +115,22 @@ export async function downloadAndExtract(
|
|||
performance.now() - toolsInstallStart,
|
||||
);
|
||||
logger.info(
|
||||
`Finished downloading and extracting CodeQL bundle to ${extractedBundlePath} (${formatDuration(
|
||||
`Finished downloading and extracting CodeQL bundle to ${dest} (${formatDuration(
|
||||
combinedDurationMs,
|
||||
)}).`,
|
||||
);
|
||||
|
||||
return {
|
||||
extractedBundlePath,
|
||||
statusReport: {
|
||||
compressionMethod,
|
||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||
...makeStreamedToolsDownloadDurations(combinedDurationMs),
|
||||
},
|
||||
compressionMethod,
|
||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||
...makeStreamedToolsDownloadDurations(combinedDurationMs),
|
||||
};
|
||||
}
|
||||
|
||||
const dest = path.join(tempDir, uuidV4());
|
||||
|
||||
const toolsDownloadStart = performance.now();
|
||||
const archivedBundlePath = await toolcache.downloadTool(
|
||||
codeqlURL,
|
||||
dest,
|
||||
undefined,
|
||||
authorization,
|
||||
headers,
|
||||
);
|
||||
|
|
@ -145,21 +142,21 @@ export async function downloadAndExtract(
|
|||
)}).`,
|
||||
);
|
||||
|
||||
let extractedBundlePath: string;
|
||||
let extractionDurationMs: number;
|
||||
|
||||
try {
|
||||
logger.info("Extracting CodeQL bundle.");
|
||||
const extractionStart = performance.now();
|
||||
extractedBundlePath = await tar.extract(
|
||||
await tar.extract(
|
||||
archivedBundlePath,
|
||||
dest,
|
||||
compressionMethod,
|
||||
tarVersion,
|
||||
logger,
|
||||
);
|
||||
extractionDurationMs = Math.round(performance.now() - extractionStart);
|
||||
logger.info(
|
||||
`Finished extracting CodeQL bundle to ${extractedBundlePath} (${formatDuration(
|
||||
`Finished extracting CodeQL bundle to ${dest} (${formatDuration(
|
||||
extractionDurationMs,
|
||||
)}).`,
|
||||
);
|
||||
|
|
@ -168,15 +165,12 @@ export async function downloadAndExtract(
|
|||
}
|
||||
|
||||
return {
|
||||
extractedBundlePath,
|
||||
statusReport: {
|
||||
compressionMethod,
|
||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||
...makeDownloadFirstToolsDownloadDurations(
|
||||
downloadDurationMs,
|
||||
extractionDurationMs,
|
||||
),
|
||||
},
|
||||
compressionMethod,
|
||||
toolsUrl: sanitizeUrlForStatusReport(codeqlURL),
|
||||
...makeDownloadFirstToolsDownloadDurations(
|
||||
downloadDurationMs,
|
||||
extractionDurationMs,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -213,6 +207,16 @@ async function downloadAndExtractZstdWithStreaming(
|
|||
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 {
|
||||
return ["github/codeql-action", "dsp-testing/codeql-cli-nightlies"].some(
|
||||
(repo) => url.startsWith(`https://github.com/${repo}/releases/download/`),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue