Repository navigation
Skip autodetected languages with no source files - #4335
therealsamyak wants to merge 3 commits into
Conversation
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
There was a problem hiding this comment.
🟡 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)
| 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()) { |
|
Hi @therealsamyak, Although this looks nice in practice, this is not going to work - at least not without further changes - because for a number of the extractors |


Fixes #4334.
When the
languagesinput 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.analyzethen fails with exit code 32.For autodetected languages only,
getLanguagesnow removes a language when the checkout has no file with an extension from the extractor'scodeql-extractor.ymlfile_types, and logs the reason. The check:datafile type (.json,.yml), because CodeQL does not count these files as JavaScript source..gitand 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 createfor Python and JavaScript fails with exit code 32. The filter keeps onlygoandactions..mjs,.html, or.vuefiles passdatabase create, and the filter keeps JavaScript.