@@ -19,26 +19,70 @@ export async function determineAutobuildLanguages(
19
19
const autobuildLanguages = config . languages . filter ( ( l ) =>
20
20
isTracedLanguage ( l , isGoExtractionReconciliationEnabled , logger )
21
21
) ;
22
- const language = autobuildLanguages [ 0 ] ;
23
22
24
- if ( ! language ) {
23
+ if ( ! autobuildLanguages ) {
25
24
logger . info (
26
25
"None of the languages in this project require extra build steps"
27
26
) ;
28
27
return undefined ;
29
28
}
30
29
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 " ) } .` ) ;
32
74
33
- if ( autobuildLanguages . length > 1 ) {
75
+ if ( autobuildLanguagesNoGo . length > 1 ) {
34
76
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
36
80
. slice ( 1 )
37
81
. join ( " and " ) } , you must replace this call with custom build steps.`
38
82
) ;
39
83
}
40
84
41
- return [ language ] ;
85
+ return languages ;
42
86
}
43
87
44
88
export async function runAutobuild (
0 commit comments