diff --git a/lib/entry-points.js b/lib/entry-points.js index 3f2c4adb9..a2b225051 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -152229,8 +152229,7 @@ function getCodeQLActionRepository(logger) { } return getRequiredEnvParam("GITHUB_ACTION_REPOSITORY"); } -async function selectDefaultBundle(action, tagName, apiDetails, options) { - const { logger } = action; +function getDefaultBundleSources(apiDetails, logger) { const codeQLActionRepository = getCodeQLActionRepository(logger); const potentialDownloadSources = [ // This GitHub instance, and this Action. @@ -152240,12 +152239,16 @@ async function selectDefaultBundle(action, tagName, apiDetails, options) { // 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 [serverURL, repository] of uniqueDownloadSources) { + return potentialDownloadSources.filter((source, index2, self2) => { + return !self2.slice(0, index2).some((other) => (0, import_fast_deep_equal.default)(source, other)); + }); +} +async function selectDefaultBundle(action, tagName, apiDetails, options) { + const { logger } = action; + for (const [serverURL, repository] of getDefaultBundleSources( + apiDetails, + logger + )) { if (serverURL === GITHUB_DOTCOM_URL && repository === CODEQL_DEFAULT_ACTION_REPOSITORY) { break; } diff --git a/src/setup-codeql.ts b/src/setup-codeql.ts index be16b6d2d..b6117343d 100644 --- a/src/setup-codeql.ts +++ b/src/setup-codeql.ts @@ -93,6 +93,27 @@ export function getCodeQLActionRepository(logger: Logger): string { return util.getRequiredEnvParam("GITHUB_ACTION_REPOSITORY"); } +/** Returns the repositories that release the default bundles, most preferred first. */ +function getDefaultBundleSources( + apiDetails: api.GitHubApiDetails, + logger: Logger, +): Array<[serverURL: string, repository: string]> { + const codeQLActionRepository = getCodeQLActionRepository(logger); + const potentialDownloadSources: Array<[string, string]> = [ + // 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. + [util.GITHUB_DOTCOM_URL, CODEQL_DEFAULT_ACTION_REPOSITORY], + ]; + // We now filter out any duplicates. + // Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork. + return potentialDownloadSources.filter((source, index, self) => { + return !self.slice(0, index).some((other) => deepEqual(source, other)); + }); +} + /** * Selects a bundle from the first release tagged `tagName` that has a compatible bundle, trying the * Action repositories on this GitHub instance before the canonical Action on GitHub.com. If we @@ -106,23 +127,10 @@ async function selectDefaultBundle( options: BundleSelectionOptions, ): Promise { const { logger } = action; - const codeQLActionRepository = getCodeQLActionRepository(logger); - 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. - [util.GITHUB_DOTCOM_URL, CODEQL_DEFAULT_ACTION_REPOSITORY], - ]; - // We now filter out any duplicates. - // Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork. - const uniqueDownloadSources = potentialDownloadSources.filter( - (source, index, self) => { - return !self.slice(0, index).some((other) => deepEqual(source, other)); - }, - ); - for (const [serverURL, repository] of uniqueDownloadSources) { + for (const [serverURL, repository] of getDefaultBundleSources( + apiDetails, + logger, + )) { // If we've reached the final case, short-circuit the API check since we know the bundle exists and is public. if ( serverURL === util.GITHUB_DOTCOM_URL &&