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
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue