@@ -11,7 +11,7 @@ import * as actionsUtil from "./actions-util";
1111import * as analyses from "./analyses" ;
1212import * as api from "./api-client" ;
1313import { getGitHubVersion , wrapApiConfigurationError } from "./api-client" ;
14- import { CodeQL , getCodeQL } from "./codeql" ;
14+ import { getCodeQL , type CodeQL } from "./codeql" ;
1515import { getConfig } from "./config-utils" ;
1616import { readDiffRangesJsonFile } from "./diff-informed-analysis-utils" ;
1717import { EnvVar } from "./environment" ;
@@ -183,6 +183,42 @@ async function shouldDisableCombineSarifFiles(
183183 return true ;
184184}
185185
186+ /**
187+ * Initialises a `CodeQL` instance that we can use to combine SARIF files.
188+ */
189+ export async function minimalInitCodeQL (
190+ logger : Logger ,
191+ gitHubVersion : GitHubVersion ,
192+ features : FeatureEnablement ,
193+ ) : Promise < CodeQL > {
194+ logger . info (
195+ "Initializing CodeQL since the 'init' Action was not called before this step." ,
196+ ) ;
197+
198+ const apiDetails = {
199+ auth : actionsUtil . getRequiredInput ( "token" ) ,
200+ externalRepoAuth : actionsUtil . getOptionalInput ( "external-repository-token" ) ,
201+ url : getRequiredEnvParam ( "GITHUB_SERVER_URL" ) ,
202+ apiURL : getRequiredEnvParam ( "GITHUB_API_URL" ) ,
203+ } ;
204+
205+ const codeQLDefaultVersionInfo = await features . getDefaultCliVersion (
206+ gitHubVersion . type ,
207+ ) ;
208+
209+ const initCodeQLResult = await initCodeQL (
210+ undefined , // There is no tools input on the upload action
211+ apiDetails ,
212+ actionsUtil . getTemporaryDirectory ( ) ,
213+ gitHubVersion . type ,
214+ codeQLDefaultVersionInfo ,
215+ features ,
216+ logger ,
217+ ) ;
218+
219+ return initCodeQLResult . codeql ;
220+ }
221+
186222// Takes a list of paths to sarif files and combines them together using the
187223// CLI `github merge-results` command when all SARIF files are produced by
188224// CodeQL. Otherwise, it will fall back to combining the files in the action.
@@ -239,34 +275,7 @@ async function combineSarifFilesUsingCLI(
239275 codeQL = await getCodeQL ( config . codeQLCmd ) ;
240276 tempDir = config . tempDir ;
241277 } else {
242- logger . info (
243- "Initializing CodeQL since the 'init' Action was not called before this step." ,
244- ) ;
245-
246- const apiDetails = {
247- auth : actionsUtil . getRequiredInput ( "token" ) ,
248- externalRepoAuth : actionsUtil . getOptionalInput (
249- "external-repository-token" ,
250- ) ,
251- url : getRequiredEnvParam ( "GITHUB_SERVER_URL" ) ,
252- apiURL : getRequiredEnvParam ( "GITHUB_API_URL" ) ,
253- } ;
254-
255- const codeQLDefaultVersionInfo = await features . getDefaultCliVersion (
256- gitHubVersion . type ,
257- ) ;
258-
259- const initCodeQLResult = await initCodeQL (
260- undefined , // There is no tools input on the upload action
261- apiDetails ,
262- tempDir ,
263- gitHubVersion . type ,
264- codeQLDefaultVersionInfo ,
265- features ,
266- logger ,
267- ) ;
268-
269- codeQL = initCodeQLResult . codeql ;
278+ codeQL = await minimalInitCodeQL ( logger , gitHubVersion , features ) ;
270279 }
271280
272281 const baseTempDir = path . resolve ( tempDir , "combined-sarif" ) ;
0 commit comments