Skip to content

Commit f17b444

Browse files
committed
Refactor getCodeQLBundleDownloadURL out of setup-codeql
1 parent 7df92f3 commit f17b444

5 files changed

Lines changed: 161 additions & 157 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 55 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package-lock.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@octokit/plugin-rest-endpoint-methods": "^18.0.0",
3636
"@octokit/plugin-retry": "^8.1.1",
3737
"archiver": "^8.0.0",
38-
"fast-deep-equal": "^3.1.3",
3938
"follow-redirects": "^1.16.0",
4039
"get-folder-size": "^5.0.0",
4140
"https-proxy-agent": "^7.0.6",

‎src/setup-codeql.ts‎

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as path from "path";
44
import { performance } from "perf_hooks";
55

66
import * as toolcache from "@actions/tool-cache";
7-
import { default as deepEqual } from "fast-deep-equal";
87
import * as semver from "semver";
98
import { v4 as uuidV4 } from "uuid";
109

@@ -35,7 +34,6 @@ import {
3534
Feature,
3635
FeatureEnablement,
3736
} from "./feature-flags";
38-
import { GITHUB_DOTCOM_URL } from "./github";
3937
import { BuiltInLanguage } from "./languages";
4038
import { Logger } from "./logging";
4139
import { getCodeQlVersionsForOverlayBaseDatabases } from "./overlay/caching";
@@ -44,10 +42,7 @@ import {
4442
logPerLanguageBundleFallback,
4543
} from "./per-language-bundles";
4644
import { getBundlePlatform } from "./platform";
47-
import {
48-
CODEQL_DEFAULT_ACTION_REPOSITORY,
49-
getCodeQLActionRepository,
50-
} from "./setup/repository";
45+
import { getCodeQLAssetDownloadURL } from "./setup/repository";
5146
import * as tar from "./tar";
5247
import {
5348
deleteToolcacheBundles,
@@ -76,64 +71,6 @@ const CODEQL_BUNDLE_VERSION_ALIAS: string[] = ["linked", "latest"];
7671
const CODEQL_NIGHTLY_TOOLS_INPUTS = ["nightly", "nightly-latest"];
7772
const CODEQL_TOOLCACHE_INPUT = "toolcache";
7873

79-
async function getCodeQLBundleDownloadURL(
80-
tagName: string,
81-
apiDetails: api.GitHubApiDetails,
82-
codeQLBundleName: string,
83-
logger: Logger,
84-
): Promise<string> {
85-
const codeQLActionRepository = getCodeQLActionRepository({
86-
logger,
87-
env: getEnv(),
88-
});
89-
const potentialDownloadSources = [
90-
// This GitHub instance, and this Action.
91-
[apiDetails.url, codeQLActionRepository],
92-
// This GitHub instance, and the canonical Action.
93-
[apiDetails.url, CODEQL_DEFAULT_ACTION_REPOSITORY],
94-
// GitHub.com, and the canonical Action.
95-
[GITHUB_DOTCOM_URL, CODEQL_DEFAULT_ACTION_REPOSITORY],
96-
];
97-
// We now filter out any duplicates.
98-
// Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork.
99-
const uniqueDownloadSources = potentialDownloadSources.filter(
100-
(source, index, self) => {
101-
return !self.slice(0, index).some((other) => deepEqual(source, other));
102-
},
103-
);
104-
for (const downloadSource of uniqueDownloadSources) {
105-
const [apiURL, repository] = downloadSource;
106-
// If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
107-
if (
108-
apiURL === GITHUB_DOTCOM_URL &&
109-
repository === CODEQL_DEFAULT_ACTION_REPOSITORY
110-
) {
111-
break;
112-
}
113-
const [repositoryOwner, repositoryName] = repository.split("/");
114-
try {
115-
const release = await api.getApiClient().rest.repos.getReleaseByTag({
116-
owner: repositoryOwner,
117-
repo: repositoryName,
118-
tag: tagName,
119-
});
120-
for (const asset of release.data.assets) {
121-
if (asset.name === codeQLBundleName) {
122-
logger.info(
123-
`Found CodeQL bundle ${codeQLBundleName} in ${repository} on ${apiURL} with URL ${asset.url}.`,
124-
);
125-
return asset.url;
126-
}
127-
}
128-
} catch (e) {
129-
logger.info(
130-
`Looked for CodeQL bundle ${codeQLBundleName} in ${repository} on ${apiURL} but got error ${e}.`,
131-
);
132-
}
133-
}
134-
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${tagName}/${codeQLBundleName}`;
135-
}
136-
13774
function tryGetBundleVersionFromTagName(
13875
tagName: string,
13976
logger: Logger,
@@ -712,9 +649,10 @@ export async function getCodeQLSource(
712649
? "zstd"
713650
: "gzip";
714651

652+
const action = { env: getEnv(), logger };
715653
const platform = getBundlePlatform();
716654
const perLanguageBundleLanguage = await getPerLanguageBundleLanguage(
717-
{ env: getEnv(), features, logger },
655+
{ ...action, features },
718656
{
719657
rawLanguages,
720658
otherLanguagePacksReason,
@@ -727,11 +665,11 @@ export async function getCodeQLSource(
727665

728666
// Resolves the combined or per-language bundle URL for the requested release.
729667
const resolveBundleURL = (language?: BuiltInLanguage) =>
730-
getCodeQLBundleDownloadURL(
731-
bundleTagName,
668+
getCodeQLAssetDownloadURL(
669+
action,
732670
apiDetails,
671+
bundleTagName,
733672
getCodeQLBundleName(compressionMethod, platform, language),
734-
logger,
735673
);
736674

737675
const combinedBundleURL = await resolveBundleURL();

0 commit comments

Comments
 (0)