Skip to content

Allow using new CodeQL languages without updating the CodeQL Action #2914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 6, 2025

Conversation

henrymercer
Copy link
Contributor

This PR revives #779, adding a few new features:

  • Correctly handle language aliases (these didn't exist at the time)
  • Determine whether or not a language is traced by looking for its tracing-config.lua file — this is what we do in the CLI too
  • Simplify the parsing logic in config-utils.ts

Commit-by-commit review recommended as one commit has a large diff from renaming the Language enum to KnownLanguage.

Caveats:

  • We don't attempt to make language handling in the start-proxy Action generic, because this Action can't assume access to the CodeQL CLI, which is the source of truth. However this is probably OK because the default behaviour of this Action, i.e. not to proxy anything, is OK for new languages.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 17:05
@henrymercer henrymercer requested a review from a team as a code owner May 30, 2025 17:05
Copilot

This comment was marked as outdated.

Base automatically changed from henrymercer/bump-minimum-codeql-2.16.6 to main June 9, 2025 21:43
@mbg mbg mentioned this pull request Jul 2, 2025
3 tasks
@henrymercer henrymercer requested review from Copilot and mbg August 5, 2025 10:07
Copilot

This comment was marked as outdated.

@Copilot Copilot AI review requested due to automatic review settings August 5, 2025 10:13
@henrymercer henrymercer added the Rebuild Re-transpile JS & re-generate workflows label Aug 5, 2025
@github-actions github-actions bot removed the Rebuild Re-transpile JS & re-generate workflows label Aug 5, 2025
Copilot

This comment was marked as outdated.

@henrymercer henrymercer force-pushed the henrymercer/language-extensibility branch from 4d8db50 to cfb8d07 Compare August 5, 2025 10:19
@Copilot Copilot AI review requested due to automatic review settings August 5, 2025 10:43
Copilot

This comment was marked as outdated.

mbg

This comment was marked as outdated.

@mbg mbg self-requested a review August 5, 2025 12:08
Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this and getting it all up-to-date after the other recent changes! Sorry for the premature review earlier as well. This broadly look good. I have a few suggestions and questions.

Should all the .includes checks for languages get the same treatment as that one check for rust?

Comment on lines +17 to +21
* In general, the CodeQL CLI is the source of truth for language aliases, and to
* allow us to more easily support new languages, we want to avoid hardcoding these
* aliases in the Action itself. However this is difficult to do in the start-proxy
* Action since this Action does not use CodeQL, so we're accepting some hardcoding
* for this Action.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't have to be addressed as part of this PR, but we only use the start-proxy in CodeQL (default setup) workflows. The start-proxy steps follows the init step, so we could rely on that here if we wanted to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your italicisation :) We could rely on that ordering, but I'd prefer not to.

@@ -342,6 +342,31 @@ async function run() {
}
core.endGroup();

// Set CODEQL_ENABLE_EXPERIMENTAL_FEATURES for rust
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do the changes here interact with #2960?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any problematic interactions, though there might be a couple of merge conflicts to address.

@Copilot Copilot AI review requested due to automatic review settings August 5, 2025 16:57
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR allows the CodeQL Action to work with new CodeQL languages without requiring updates to the Action itself. The changes generalize language handling by querying the CodeQL CLI as the source of truth for supported languages and language aliases, instead of hardcoding them in the Action.

Key Changes

  • Replaces the hardcoded Language enum with a generic Language type and a KnownLanguage enum for languages requiring special handling
  • Implements dynamic language detection using CodeQL CLI's betterResolveLanguages() and isTracedLanguage() methods
  • Simplifies language parsing logic by delegating alias resolution to the CLI

Reviewed Changes

Copilot reviewed 45 out of 67 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/languages.ts Refactors from hardcoded enum to generic type with known language subset
src/config-utils.ts Implements dynamic language support using CLI as source of truth
src/codeql.ts Adds methods to determine if languages are traced/scanned
src/start-proxy.ts Maintains hardcoded aliases for proxy action (CLI not available)
src/util.ts Adds async utility functions and fixes String() wrapper usage
Multiple test files Updates all references from Language to KnownLanguage enum
lib/ files Generated JavaScript code reflecting TypeScript changes

core.exportVariable(EnvVar.FEATURE_MULTI_LANGUAGE, "false");
core.exportVariable(EnvVar.FEATURE_SANDWICH, "false");
core.exportVariable(EnvVar.FEATURE_SARIF_COMBINE, "true");
core.exportVariable(EnvVar.FEATURE_WILL_UPLOAD, "true");
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The removal of String() wrapper is good for consistency, but these environment variable values should use boolean strings consistently. Consider using a constant or helper function to ensure consistency across the codebase.

Suggested change
core.exportVariable(EnvVar.FEATURE_WILL_UPLOAD, "true");
core.exportVariable(EnvVar.FEATURE_MULTI_LANGUAGE, BOOLEAN_FALSE);
core.exportVariable(EnvVar.FEATURE_SANDWICH, BOOLEAN_FALSE);
core.exportVariable(EnvVar.FEATURE_SARIF_COMBINE, BOOLEAN_TRUE);
core.exportVariable(EnvVar.FEATURE_WILL_UPLOAD, BOOLEAN_TRUE);

Copilot uses AI. Check for mistakes.

@@ -541,7 +541,7 @@ export function validateSarifFileSchema(
);
}

if (errors.length) {
if (errors.length > 0) {
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from errors.length to errors.length > 0 is more explicit and consistent with the similar change in other files, improving code readability.

Copilot uses AI. Check for mistakes.

return (languagesInput || "")
.split(",")
.map((x) => x.trim().toLowerCase())
.filter((x) => x.length > 0);
}
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function duplicates logic that was previously inline in getRawLanguages. Consider extracting this to a shared utility function to avoid code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

}
}
return supportedLanguages;
}
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called within language detection logic that could be called frequently. Consider caching the result to avoid repeated calls to betterResolveLanguages() within the same execution context.

Copilot uses AI. Check for mistakes.

@@ -240,7 +240,10 @@ async function sendCompletedStatusReport(
packs: JSON.stringify(packs),
trap_cache_languages: Object.keys(config.trapCaches).join(","),
trap_cache_download_size_bytes: Math.round(
await getTotalCacheSize(Object.values(config.trapCaches), logger),
await getTotalCacheSize(
Copy link
Preview

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter for undefined values suggests that config.trapCaches may contain undefined entries. Consider updating the type definition or initialization logic to prevent undefined values from being added to trapCaches in the first place.

Note: See the diff below for a potential fix:

@@ -238,9 +238,13 @@
       paths_ignore: pathsIgnore,
       queries: queries.join(","),
       packs: JSON.stringify(packs),
-      trap_cache_languages: Object.keys(config.trapCaches).join(","),
+      // Only include languages for which the trap cache is defined
+      trap_cache_languages: Object.keys(config.trapCaches)
+        .filter((lang) => config.trapCaches[lang] !== undefined)
+        .join(","),
       trap_cache_download_size_bytes: Math.round(
         await getTotalCacheSize(
+          // Only include defined trap cache entries
           Object.values(config.trapCaches).filter((x) => x !== undefined),
           logger,
         ),

Copilot uses AI. Check for mistakes.

@henrymercer henrymercer requested a review from mbg August 5, 2025 17:11
mbg
mbg previously approved these changes Aug 5, 2025
Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the feedback! I think the change of type for the trap caches is good. :shipit:

src/languages.ts Outdated
Comment on lines 1 to 2
/** A language supported by CodeQL. */
export type Language = string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Technically this now represents any language identifier, whether supported or not

@henrymercer henrymercer merged commit 60bf7df into main Aug 6, 2025
282 checks passed
@henrymercer henrymercer deleted the henrymercer/language-extensibility branch August 6, 2025 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants