Skip to content

Skip autodetected languages with no source files - #4335

Open
therealsamyak wants to merge 3 commits into
github:mainfrom
therealsamyak:fix/4334-skip-languages-without-files
Open

therealsamyak wants to merge 3 commits into
github:mainfrom
therealsamyak:fix/4334-skip-languages-without-files

Conversation

@therealsamyak

@therealsamyak therealsamyak commented Nov 19, 2026 •

Copy link
Copy Markdown

Fixes #4334.

When the languages input is empty, the Action autodetects languages with the GitHub languages API. That API reports the default branch's languages and updates in the background, so it can still report a language after its last file is removed. analyze then fails with exit code 32.

For autodetected languages only, getLanguages now removes a language when the checkout has no file with an extension from the extractor's codeql-extractor.yml file_types, and logs the reason. The check:

  • Ignores the JavaScript extractor's data file type (.json, .yml), because CodeQL does not count these files as JavaScript source.
  • Keeps a language whose extractor declares no file types.
  • Skips .git and stops when it finds every extension.

Validation with CodeQL CLI 2.27.5, on a checkout with only main.go, go.mod, and a workflow file:

  • database create for Python and JavaScript fails with exit code 32. The filter keeps only go and actions.
  • JavaScript checkouts with only .mjs, .html, or .vue files pass database create, and the filter keeps JavaScript.

Language autodetection uses the GitHub languages API. That API reports
the languages of the default branch, and GitHub updates the data in
the background. After the last file of a language is removed, the API
can still report that language. The Action then creates a database for
it, and `analyze` fails with exit code 32 because CodeQL sees no source
code.

When languages are autodetected, check the checkout for files with the
extensions that each extractor declares in its `codeql-extractor.yml`.
Skip a language if no such file exists, and log the reason. Ignore the
JavaScript extractor's `data` file type, because CodeQL does not count
`.json` or `.yml` files as JavaScript source. Languages from the
`languages` input are not changed.

Fixes github#4334
@therealsamyak
therealsamyak requested a review from a team as a code owner November 19, 2026 20:22
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 20:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Autodetection can silently drop languages with build-generated or symlinked sources before tracing begins, leaving code unanalyzed.

3 open issues
What changed in this PR

Addresses #4334 by checking the checkout before selecting autodetected languages, reducing analysis failures caused by stale GitHub language statistics.

Changes:

  • Reads extractor file extensions and filters out autodetected languages without matching files, excluding JavaScript data-file types.
  • Preserves explicit language inputs and languages without declared file types.
  • Adds unit tests, a release note, and regenerated bundled JavaScript.
File Description
unreleased-change-notes/​skip-languages-without-files.md Documents the autodetection behavior change.
src/​languages/​source-files.ts Adds extractor metadata parsing and source-file filtering.
src/​languages/​source-files.test.ts Tests extension parsing, traversal, and filtering.
src/​config-utils.ts Applies source-file filtering to autodetected languages.
src/​config-utils.test.ts Tests autodetection filtering and explicit-input preservation.
lib/​entry-points.js Regenerated bundle containing the TypeScript changes.

Review effort: Balanced (adaptive)

Comment thread src/config-utils.ts
Comment on lines +293 to +295
if (autodetected) {
languages = filterLanguagesWithSourceFiles(
languages,
): Set<string> {
const found = new Set<string>();
const pendingDirs = [rootDir];
while (pendingDirs.length > 0 && found.size < extensions.size) {
if (entry.name !== ".git") {
pendingDirs.push(path.join(dir, entry.name));
}
} else if (entry.isFile()) {

This branch has not been deployed

No deployments
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.

Language autodetection selects a language that has no files in the checkout

2 participants