Repository navigation
Explain how to override language autodetection in CodeQL errors - #4335
therealsamyak wants to merge 6 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 |
The previous fix filtered autodetected languages in init by matching the extensions in each extractor's codeql-extractor.yml file_types. That list is not complete. For example, the JavaScript extractor also extracts .xsjs and .xsjslib files, so a repository with only such files would lose JavaScript analysis. The pre-build check also missed sources that the build generates, and it walked the whole checkout. Use CodeQL's own result instead. When database finalization fails with the no-source-code-seen error (exit code 32) for an autodetected language that CodeQL extracts by reading the checkout, analyze now skips that language with a warning and analyzes the others. Languages from the languages input and traced languages still fail, because for them the error usually means a build or configuration problem. If no autodetected language has source code, analyze still fails. To support this, init saves whether it autodetected the languages in the new languagesAutodetected config field, and wrapCliConfigurationError returns a CliConfigurationError that keeps the CLI error category.
|
The updated change is also not correct, as CodeQL might not have been able to detect code for other reasons, e.g., a compiler version mismatch. That then is actually an issue with CodeQL that will need to be fixed there. |
Keep CodeQL finalization failures visible. A no-source error can also indicate a compiler or extractor failure, so it cannot justify skipping analysis. Point users to the init languages input when automatic detection selects a language that is absent from the checkout.
Bring in the latest release mergeback and verify the generated bundle against the current base.


Related to #4334.
The GitHub languages API describes the default branch. Automatic language detection can therefore select a language that is absent from the checkout.
When CodeQL reports that it saw no source code, the Action preserves the original error. It adds guidance to set the
languagesinput oninitif automatic detection selected a language that is absent. A no-source error can also indicate an extraction or build problem. In CodeQL CLI 2.27.5, an absent JavaScript source and a malformed.xsjsfile can produce the same finalization error.This PR provides troubleshooting guidance for #4334. Automatic skipping requires CodeQL to distinguish missing sources from extraction failures.
Risk assessment
This change affects the text of no-source-code errors. Language selection and analysis behavior remain unchanged.
Which use cases does this change impact?
Code Scanning and Code Quality runs can see the additional guidance on GitHub.com and GitHub Enterprise Server. Advanced setup workflows can use the
languagesinput to select the languages to analyze.How did/will you validate this change?
npm run build,npm run lint, andnpm run testpass.If something goes wrong after this change is released, what are the mitigation and rollback strategies?
Revert the message change to restore the previous wording.
How will you know if something goes wrong after this change is released?
The guidance appears in the failed workflow's error message. The regression test checks that the error remains a configuration error.
Are there any special considerations for merging or releasing this change?
No changes in other repositories are required for the guidance.
Merge / deployment checklist
unreleased-change-notes/no-source-code-language-guidance.md.