From d8b6f2a09b50947d13938f5ef83199b1aa738845 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Wed, 30 Sep 2026 15:24:35 +0100 Subject: [PATCH] Always use the combined bundle in `setup-codeql` Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- lib/entry-points.js | 13 ++++++++----- src/codeql.ts | 5 +++-- src/per-language-bundles.test.ts | 25 ++++++++++++++----------- src/per-language-bundles.ts | 14 +++++++++----- src/setup-codeql-action.ts | 7 ++++++- src/setup-codeql.ts | 5 +++-- 6 files changed, 43 insertions(+), 26 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index ad390ee7a..8f1895406 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -151644,6 +151644,9 @@ async function getPerLanguageBundleLanguage({ if (!await features.getValue("per_language_bundles" /* PerLanguageBundles */)) { return explain(`the ${"per_language_bundles" /* PerLanguageBundles */} feature is disabled`); } + if (otherLanguagePacksReason !== void 0) { + return explain(otherLanguagePacksReason); + } if (rawLanguages?.length !== 1) { return explain( `exactly one language must be requested via the 'languages' input, but ${rawLanguages?.length ?? 0} were` @@ -151653,9 +151656,6 @@ async function getPerLanguageBundleLanguage({ if (language === void 0) { return explain(`'${rawLanguages[0]}' is not a known CodeQL language`); } - if (otherLanguagePacksReason !== void 0) { - return explain(otherLanguagePacksReason); - } if (compressionMethod !== "zstd") { return explain(`the bundle would be downloaded as '${compressionMethod}'`); } @@ -163402,8 +163402,11 @@ async function run6(actionState) { gitHubVersion.type, codeQLDefaultVersionInfo, rawLanguages, - void 0, - // otherLanguagePacksReason: this Action doesn't take a query configuration + // CodeQL resolves the dependencies of queries that aren't in compiled packs from the bundle, + // so the queries that the workflow runs with this CLI may need library packs for languages + // other than those in the `languages` input. That input therefore only informs the choice of + // CLI version. + "the 'setup-codeql' Action can't tell whether the queries that the workflow runs will need library packs for other languages", analysisKinds.length === 1 && analysisKinds[0] === "code-scanning" /* CodeScanning */, features, logger diff --git a/src/codeql.ts b/src/codeql.ts index 00985c994..6df604e39 100644 --- a/src/codeql.ts +++ b/src/codeql.ts @@ -302,8 +302,9 @@ export function isDiskConfigurationError(e: unknown): boolean { * @param variant * @param defaultCliVersion * @param rawLanguages Raw set of languages. - * @param otherLanguagePacksReason Why the configured queries may need library packs for languages - * other than `rawLanguages`, if they might. See `getOtherLanguagePacksReason`. + * @param otherLanguagePacksReason Why the CodeQL CLI may need packs for languages other than + * `rawLanguages`, or `undefined` if it won't. If defined, the combined bundle is used. See + * `PerLanguageBundleOptions.otherLanguagePacksReason`. * @param useOverlayAwareDefaultCliVersion Whether to select an overlay-aware default CLI version. * @param features Information about the features that are enabled. * @param logger diff --git a/src/per-language-bundles.test.ts b/src/per-language-bundles.test.ts index 3dc97c70f..b6c945160 100644 --- a/src/per-language-bundles.test.ts +++ b/src/per-language-bundles.test.ts @@ -84,18 +84,21 @@ test("getPerLanguageBundleLanguage requires a known language", async (t) => { t.is(await checkEligibility({ rawLanguages: ["cobol"] }), undefined); }); -test("getPerLanguageBundleLanguage explains queries that may need library packs for other languages", async (t) => { - const messages: LoggedMessage[] = []; - const language = await checkEligibility( - { otherLanguagePacksReason: "an example reason" }, - { logger: getRecordingLogger(messages, { logToConsole: false }) }, - ); +test("getPerLanguageBundleLanguage explains why the CodeQL CLI may need packs for other languages before checking the languages", async (t) => { + // Without a language, the explanation would otherwise suggest requesting a single language. + for (const rawLanguages of [["java"], undefined]) { + const messages: LoggedMessage[] = []; + const language = await checkEligibility( + { rawLanguages, otherLanguagePacksReason: "an example reason" }, + { logger: getRecordingLogger(messages, { logToConsole: false }) }, + ); - t.is(language, undefined); - t.deepEqual( - messages.map((message) => message.message), - ["Not using a per-language CodeQL bundle since an example reason."], - ); + t.is(language, undefined); + t.deepEqual( + messages.map((message) => message.message), + ["Not using a per-language CodeQL bundle since an example reason."], + ); + } }); test("getPerLanguageBundleLanguage requires a zstd bundle", async (t) => { diff --git a/src/per-language-bundles.ts b/src/per-language-bundles.ts index b1aced586..dbde59b21 100644 --- a/src/per-language-bundles.ts +++ b/src/per-language-bundles.ts @@ -111,7 +111,9 @@ export interface PerLanguageBundleOptions { /** Explicit input only: autodetection needs a CLI instance. */ rawLanguages: string[] | undefined; /** - * Why the configured queries may need library packs for other languages, if they might. See + * Why the CodeQL CLI may need packs for other languages, for example because of the configured + * queries, or `undefined` if it won't. If defined, the combined bundle is used, and this reason is + * logged to complete the sentence "Not using a per-language CodeQL bundle since ...". See * `getOtherLanguagePacksReason`. */ otherLanguagePacksReason: string | undefined; @@ -153,6 +155,12 @@ export async function getPerLanguageBundleLanguage( return explain(`the ${Feature.PerLanguageBundles} feature is disabled`); } + // This reason applies whichever languages were requested, so check it first to avoid suggesting + // that requesting a single language would be enough. + if (otherLanguagePacksReason !== undefined) { + return explain(otherLanguagePacksReason); + } + if (rawLanguages?.length !== 1) { return explain( `exactly one language must be requested via the 'languages' input, but ${ @@ -166,10 +174,6 @@ export async function getPerLanguageBundleLanguage( return explain(`'${rawLanguages[0]}' is not a known CodeQL language`); } - if (otherLanguagePacksReason !== undefined) { - return explain(otherLanguagePacksReason); - } - if (compressionMethod !== "zstd") { // Per-language bundles are only published as zstd archives. return explain(`the bundle would be downloaded as '${compressionMethod}'`); diff --git a/src/setup-codeql-action.ts b/src/setup-codeql-action.ts index c50f67c41..23a9c65eb 100644 --- a/src/setup-codeql-action.ts +++ b/src/setup-codeql-action.ts @@ -165,7 +165,12 @@ async function run( gitHubVersion.type, codeQLDefaultVersionInfo, rawLanguages, - undefined, // otherLanguagePacksReason: this Action doesn't take a query configuration + // CodeQL resolves the dependencies of queries that aren't in compiled packs from the bundle, + // so the queries that the workflow runs with this CLI may need library packs for languages + // other than those in the `languages` input. That input therefore only informs the choice of + // CLI version. + "the 'setup-codeql' Action can't tell whether the queries that the workflow runs will need " + + "library packs for other languages", analysisKinds.length === 1 && analysisKinds[0] === AnalysisKind.CodeScanning, features, diff --git a/src/setup-codeql.ts b/src/setup-codeql.ts index 31f09f0c2..f2ce959a8 100644 --- a/src/setup-codeql.ts +++ b/src/setup-codeql.ts @@ -377,8 +377,9 @@ async function resolveDefaultCliVersion( * @param toolsInput The argument provided for the `tools` input, if any. * @param defaultCliVersion The default CLI version that's linked to the CodeQL Action. * @param rawLanguages Raw set of languages. - * @param otherLanguagePacksReason Why the configured queries may need library packs for languages - * other than `rawLanguages`, if they might. See `getOtherLanguagePacksReason`. + * @param otherLanguagePacksReason Why the CodeQL CLI may need packs for languages other than + * `rawLanguages`, or `undefined` if it won't. If defined, the combined bundle is used. See + * `PerLanguageBundleOptions.otherLanguagePacksReason`. * @param useOverlayAwareDefaultCliVersion Whether to select an overlay-aware default CLI version. * @param apiDetails Information about the GitHub API. * @param variant The GitHub variant we are running on.