Repository navigation
Skip autodetected languages with no source files - #4335
Open
therealsamyak wants to merge 3 commits into
Open
therealsamyak wants to merge 3 commits into
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
Contributor
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)
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.