mirror of
https://github.com/github/codeql-action.git
synced 2026-10-31 01:49:43 +00:00
Refactor getCodeQLBundleDownloadURL out of setup-codeql
This commit is contained in:
142
lib/entry-points.js
generated
142
lib/entry-points.js
generated
@@ -107096,41 +107096,6 @@ var require_tool_cache = __commonJS({
|
||||
}
|
||||
});
|
||||
|
||||
// node_modules/fast-deep-equal/index.js
|
||||
var require_fast_deep_equal = __commonJS({
|
||||
"node_modules/fast-deep-equal/index.js"(exports2, module2) {
|
||||
"use strict";
|
||||
module2.exports = function equal(a, b) {
|
||||
if (a === b) return true;
|
||||
if (a && b && typeof a == "object" && typeof b == "object") {
|
||||
if (a.constructor !== b.constructor) return false;
|
||||
var length, i, keys;
|
||||
if (Array.isArray(a)) {
|
||||
length = a.length;
|
||||
if (length != b.length) return false;
|
||||
for (i = length; i-- !== 0; )
|
||||
if (!equal(a[i], b[i])) return false;
|
||||
return true;
|
||||
}
|
||||
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
|
||||
if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
|
||||
if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
|
||||
keys = Object.keys(a);
|
||||
length = keys.length;
|
||||
if (length !== Object.keys(b).length) return false;
|
||||
for (i = length; i-- !== 0; )
|
||||
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
|
||||
for (i = length; i-- !== 0; ) {
|
||||
var key = keys[i];
|
||||
if (!equal(a[key], b[key])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return a !== a && b !== b;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// node_modules/follow-redirects/debug.js
|
||||
var require_debug3 = __commonJS({
|
||||
"node_modules/follow-redirects/debug.js"(exports2, module2) {
|
||||
@@ -175290,7 +175255,6 @@ var fs14 = __toESM(require("fs"));
|
||||
var path13 = __toESM(require("path"));
|
||||
var import_perf_hooks4 = require("perf_hooks");
|
||||
var toolcache3 = __toESM(require_tool_cache());
|
||||
var import_fast_deep_equal = __toESM(require_fast_deep_equal());
|
||||
var semver9 = __toESM(require_semver2());
|
||||
|
||||
// src/codeql-bundle.ts
|
||||
@@ -175757,6 +175721,55 @@ function getCodeQLActionRepository(action) {
|
||||
}
|
||||
return action.env.getRequired("GITHUB_ACTION_REPOSITORY" /* GITHUB_ACTION_REPOSITORY */);
|
||||
}
|
||||
var DEFAULT_DOWNLOAD_SOURCE = [
|
||||
GITHUB_DOTCOM_URL,
|
||||
CODEQL_DEFAULT_ACTION_REPOSITORY
|
||||
];
|
||||
var isSameDownloadSource = ([srcUrl, srcRepo], [otherUrl, otherRepo]) => {
|
||||
return srcUrl === otherUrl && srcRepo === otherRepo;
|
||||
};
|
||||
async function getCodeQLAssetDownloadURL(action, apiDetails, tagName, assetName, assetKind = "CodeQL bundle") {
|
||||
const codeQLActionRepository = getCodeQLActionRepository(action);
|
||||
const potentialDownloadSources = [
|
||||
// This GitHub instance, and this Action.
|
||||
[apiDetails.url, codeQLActionRepository],
|
||||
// This GitHub instance, and the canonical Action.
|
||||
[apiDetails.url, CODEQL_DEFAULT_ACTION_REPOSITORY],
|
||||
// GitHub.com, and the canonical Action.
|
||||
DEFAULT_DOWNLOAD_SOURCE
|
||||
];
|
||||
const uniqueDownloadSources = potentialDownloadSources.filter(
|
||||
(source, index2, self2) => {
|
||||
return !self2.slice(0, index2).some((other) => isSameDownloadSource(source, other));
|
||||
}
|
||||
);
|
||||
for (const [apiURL, repository] of uniqueDownloadSources) {
|
||||
if (isSameDownloadSource(DEFAULT_DOWNLOAD_SOURCE, [apiURL, repository])) {
|
||||
break;
|
||||
}
|
||||
const [repositoryOwner, repositoryName] = repository.split("/");
|
||||
try {
|
||||
const release2 = await getApiClient().rest.repos.getReleaseByTag({
|
||||
owner: repositoryOwner,
|
||||
repo: repositoryName,
|
||||
tag: tagName
|
||||
});
|
||||
for (const asset of release2.data.assets) {
|
||||
if (asset.name === assetName) {
|
||||
action.logger.info(
|
||||
`Found ${assetKind} ${assetName} in ${repository} on ${apiURL} with URL ${asset.url}.`
|
||||
);
|
||||
return asset.url;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
action.logger.info(
|
||||
`Looked for ${assetKind} ${assetName} in ${repository} on ${apiURL} but got error ${e}.`
|
||||
);
|
||||
}
|
||||
}
|
||||
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${tagName}/${assetName}`;
|
||||
}
|
||||
|
||||
// src/tar.ts
|
||||
var import_child_process = require("child_process");
|
||||
@@ -176154,52 +176167,6 @@ var CODEQL_NIGHTLIES_REPOSITORY_NAME = "codeql-cli-nightlies";
|
||||
var CODEQL_BUNDLE_VERSION_ALIAS = ["linked", "latest"];
|
||||
var CODEQL_NIGHTLY_TOOLS_INPUTS = ["nightly", "nightly-latest"];
|
||||
var CODEQL_TOOLCACHE_INPUT = "toolcache";
|
||||
async function getCodeQLBundleDownloadURL(tagName, apiDetails, codeQLBundleName, logger2) {
|
||||
const codeQLActionRepository = getCodeQLActionRepository({
|
||||
logger: logger2,
|
||||
env: getEnv()
|
||||
});
|
||||
const potentialDownloadSources = [
|
||||
// This GitHub instance, and this Action.
|
||||
[apiDetails.url, codeQLActionRepository],
|
||||
// This GitHub instance, and the canonical Action.
|
||||
[apiDetails.url, CODEQL_DEFAULT_ACTION_REPOSITORY],
|
||||
// GitHub.com, and the canonical Action.
|
||||
[GITHUB_DOTCOM_URL, CODEQL_DEFAULT_ACTION_REPOSITORY]
|
||||
];
|
||||
const uniqueDownloadSources = potentialDownloadSources.filter(
|
||||
(source, index2, self2) => {
|
||||
return !self2.slice(0, index2).some((other) => (0, import_fast_deep_equal.default)(source, other));
|
||||
}
|
||||
);
|
||||
for (const downloadSource of uniqueDownloadSources) {
|
||||
const [apiURL, repository] = downloadSource;
|
||||
if (apiURL === GITHUB_DOTCOM_URL && repository === CODEQL_DEFAULT_ACTION_REPOSITORY) {
|
||||
break;
|
||||
}
|
||||
const [repositoryOwner, repositoryName] = repository.split("/");
|
||||
try {
|
||||
const release2 = await getApiClient().rest.repos.getReleaseByTag({
|
||||
owner: repositoryOwner,
|
||||
repo: repositoryName,
|
||||
tag: tagName
|
||||
});
|
||||
for (const asset of release2.data.assets) {
|
||||
if (asset.name === codeQLBundleName) {
|
||||
logger2.info(
|
||||
`Found CodeQL bundle ${codeQLBundleName} in ${repository} on ${apiURL} with URL ${asset.url}.`
|
||||
);
|
||||
return asset.url;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
logger2.info(
|
||||
`Looked for CodeQL bundle ${codeQLBundleName} in ${repository} on ${apiURL} but got error ${e}.`
|
||||
);
|
||||
}
|
||||
}
|
||||
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${tagName}/${codeQLBundleName}`;
|
||||
}
|
||||
function tryGetBundleVersionFromTagName(tagName, logger2) {
|
||||
const match2 = tagName.match(/^codeql-bundle-(.+)$/);
|
||||
if (match2 === null || match2.length < 2) {
|
||||
@@ -176557,9 +176524,10 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, rawLanguages, othe
|
||||
);
|
||||
}
|
||||
compressionMethod = cliVersion2 !== void 0 && await useZstdBundle(cliVersion2, tarSupportsZstd) ? "zstd" : "gzip";
|
||||
const action = { env: getEnv(), logger: logger2 };
|
||||
const platform2 = getBundlePlatform();
|
||||
const perLanguageBundleLanguage = await getPerLanguageBundleLanguage(
|
||||
{ env: getEnv(), features, logger: logger2 },
|
||||
{ ...action, features },
|
||||
{
|
||||
rawLanguages,
|
||||
otherLanguagePacksReason,
|
||||
@@ -176569,11 +176537,11 @@ async function getCodeQLSource(toolsInput, defaultCliVersion, rawLanguages, othe
|
||||
variant
|
||||
}
|
||||
);
|
||||
const resolveBundleURL = (language) => getCodeQLBundleDownloadURL(
|
||||
bundleTagName,
|
||||
const resolveBundleURL = (language) => getCodeQLAssetDownloadURL(
|
||||
action,
|
||||
apiDetails,
|
||||
getCodeQLBundleName(compressionMethod, platform2, language),
|
||||
logger2
|
||||
bundleTagName,
|
||||
getCodeQLBundleName(compressionMethod, platform2, language)
|
||||
);
|
||||
const combinedBundleURL = await resolveBundleURL();
|
||||
if (perLanguageBundleLanguage !== void 0) {
|
||||
|
||||
Reference in New Issue
Block a user