Skip to content

Commit

Permalink
Ensure backwards compat for multi-language builds with Go reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Sep 12, 2022
1 parent 0d2fa3c commit 40e0374
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 13 deletions.
50 changes: 44 additions & 6 deletions lib/autobuild.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/autobuild.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 50 additions & 6 deletions src/autobuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,70 @@ export async function determineAutobuildLanguages(
const autobuildLanguages = config.languages.filter((l) =>
isTracedLanguage(l, isGoExtractionReconciliationEnabled, logger)
);
const language = autobuildLanguages[0];

if (!language) {
if (!autobuildLanguages) {
logger.info(
"None of the languages in this project require extra build steps"
);
return undefined;
}

logger.debug(`Detected dominant traced language: ${language}`);
/**
* Additionally autobuild Go in the autobuild Action to ensure backwards
* compatibility for users performing a multi-language build within a single
* job.
*
* For example, consider a user with the following workflow file:
*
* ```yml
* - uses: github/codeql-action/init@v2
* with:
* languages: go, java
* - uses: github/codeql-action/autobuild@v2
* - uses: github/codeql-action/analyze@v2
* ```
*
* - With Go extraction disabled, we will run the Java autobuilder in the
* autobuild Action, ensuring we extract both Java and Go code.
* - With Go extraction enabled, taking the previous behavior we'd run the Go
* autobuilder, since Go is first on the list of languages. We wouldn't run
* the Java autobuilder at all and so we'd only extract Go code.
*
* We therefore introduce a special case here such that we'll autobuild Go
* in addition to the primary non-Go traced language in the autobuild Action.
*
* This special case behavior should be removed as part of the next major
* version of the CodeQL Action.
*/
const autobuildLanguagesNoGo = autobuildLanguages.filter(
(l) => l !== Language.go
);

const languages: Language[] = [];
// First run the autobuilder for the first non-Go traced language, if one
// exists.
if (autobuildLanguagesNoGo[0] !== undefined) {
languages.push(autobuildLanguagesNoGo[0]);
}
// If Go is requested, run the Go autobuilder last to ensure it doesn't
// interfere with the other autobuilder.
if (autobuildLanguages.length !== autobuildLanguagesNoGo.length) {
languages.push(Language.go);
}

logger.debug(`Will autobuild ${languages.join(" and ")}.`);

if (autobuildLanguages.length > 1) {
if (autobuildLanguagesNoGo.length > 1) {
logger.warning(
`We will only automatically build ${language} code. If you wish to scan ${autobuildLanguages
`We will only automatically build ${languages.join(
" and "
)} code. If you wish to scan ${autobuildLanguagesNoGo
.slice(1)
.join(" and ")}, you must replace this call with custom build steps.`
);
}

return [language];
return languages;
}

export async function runAutobuild(
Expand Down

0 comments on commit 40e0374

Please sign in to comment.