@@ -19,26 +19,70 @@ export async function determineAutobuildLanguages(
1919 const autobuildLanguages = config . languages . filter ( ( l ) =>
2020 isTracedLanguage ( l , isGoExtractionReconciliationEnabled , logger )
2121 ) ;
22- const language = autobuildLanguages [ 0 ] ;
2322
24- if ( ! language ) {
23+ if ( ! autobuildLanguages ) {
2524 logger . info (
2625 "None of the languages in this project require extra build steps"
2726 ) ;
2827 return undefined ;
2928 }
3029
31- logger . debug ( `Detected dominant traced language: ${ language } ` ) ;
30+ /**
31+ * Additionally autobuild Go in the autobuild Action to ensure backwards
32+ * compatibility for users performing a multi-language build within a single
33+ * job.
34+ *
35+ * For example, consider a user with the following workflow file:
36+ *
37+ * ```yml
38+ * - uses: github/codeql-action/init@v2
39+ * with:
40+ * languages: go, java
41+ * - uses: github/codeql-action/autobuild@v2
42+ * - uses: github/codeql-action/analyze@v2
43+ * ```
44+ *
45+ * - With Go extraction disabled, we will run the Java autobuilder in the
46+ * autobuild Action, ensuring we extract both Java and Go code.
47+ * - With Go extraction enabled, taking the previous behavior we'd run the Go
48+ * autobuilder, since Go is first on the list of languages. We wouldn't run
49+ * the Java autobuilder at all and so we'd only extract Go code.
50+ *
51+ * We therefore introduce a special case here such that we'll autobuild Go
52+ * in addition to the primary non-Go traced language in the autobuild Action.
53+ *
54+ * This special case behavior should be removed as part of the next major
55+ * version of the CodeQL Action.
56+ */
57+ const autobuildLanguagesNoGo = autobuildLanguages . filter (
58+ ( l ) => l !== Language . go
59+ ) ;
60+
61+ const languages : Language [ ] = [ ] ;
62+ // First run the autobuilder for the first non-Go traced language, if one
63+ // exists.
64+ if ( autobuildLanguagesNoGo [ 0 ] !== undefined ) {
65+ languages . push ( autobuildLanguagesNoGo [ 0 ] ) ;
66+ }
67+ // If Go is requested, run the Go autobuilder last to ensure it doesn't
68+ // interfere with the other autobuilder.
69+ if ( autobuildLanguages . length !== autobuildLanguagesNoGo . length ) {
70+ languages . push ( Language . go ) ;
71+ }
72+
73+ logger . debug ( `Will autobuild ${ languages . join ( " and " ) } .` ) ;
3274
33- if ( autobuildLanguages . length > 1 ) {
75+ if ( autobuildLanguagesNoGo . length > 1 ) {
3476 logger . warning (
35- `We will only automatically build ${ language } code. If you wish to scan ${ autobuildLanguages
77+ `We will only automatically build ${ languages . join (
78+ " and "
79+ ) } code. If you wish to scan ${ autobuildLanguagesNoGo
3680 . slice ( 1 )
3781 . join ( " and " ) } , you must replace this call with custom build steps.`
3882 ) ;
3983 }
4084
41- return [ language ] ;
85+ return languages ;
4286}
4387
4488export async function runAutobuild (
0 commit comments