@@ -181,6 +181,151 @@ for (const {
181181 ) ;
182182}
183183
184+ const CLI_VERSION_TOOLS_INPUT_TEST_CASES = [
185+ {
186+ toolsInput : "2.20.1" ,
187+ platform : "linux" ,
188+ tarSupportsZstd : true ,
189+ expectedBundleName : "codeql-bundle-linux64.tar.zst" ,
190+ expectedCompressionMethod : "zstd" ,
191+ } ,
192+ {
193+ toolsInput : "v2.20.1" ,
194+ platform : "darwin" ,
195+ tarSupportsZstd : true ,
196+ expectedBundleName : "codeql-bundle-osx64.tar.zst" ,
197+ expectedCompressionMethod : "zstd" ,
198+ } ,
199+ {
200+ toolsInput : "v2.20.1" ,
201+ platform : "win32" ,
202+ tarSupportsZstd : true ,
203+ expectedBundleName : "codeql-bundle-win64.tar.gz" ,
204+ expectedCompressionMethod : "gzip" ,
205+ } ,
206+ {
207+ toolsInput : "2.20.1" ,
208+ platform : "linux" ,
209+ tarSupportsZstd : false ,
210+ expectedBundleName : "codeql-bundle-linux64.tar.gz" ,
211+ expectedCompressionMethod : "gzip" ,
212+ } ,
213+ {
214+ // CodeQL versions older than 2.19.0 don't have zstd bundles, so gzip should be selected
215+ // even though the runner supports zstd.
216+ toolsInput : "v2.18.4" ,
217+ platform : "linux" ,
218+ tarSupportsZstd : true ,
219+ expectedBundleName : "codeql-bundle-linux64.tar.gz" ,
220+ expectedCompressionMethod : "gzip" ,
221+ } ,
222+ ] as const ;
223+
224+ for ( const {
225+ toolsInput,
226+ platform,
227+ tarSupportsZstd,
228+ expectedBundleName,
229+ expectedCompressionMethod,
230+ } of CLI_VERSION_TOOLS_INPUT_TEST_CASES ) {
231+ test . serial (
232+ `getCodeQLSource selects ${ expectedBundleName } for 'tools: ${ toolsInput } '` ,
233+ async ( t ) => {
234+ const features = createFeatures ( [ ] ) ;
235+ sinon . stub ( process , "platform" ) . value ( platform ) ;
236+
237+ await withTmpDir ( async ( tmpDir ) => {
238+ setupActionsVars ( tmpDir , tmpDir ) ;
239+ const source = await setupCodeql . getCodeQLSource (
240+ toolsInput ,
241+ SAMPLE_DEFAULT_CLI_VERSION ,
242+ undefined , // rawLanguages
243+ false , // useOverlayAwareDefaultCliVersion
244+ SAMPLE_DOTCOM_API_DETAILS ,
245+ GitHubVariant . DOTCOM ,
246+ tarSupportsZstd ,
247+ features ,
248+ getRunnerLogger ( true ) ,
249+ ) ;
250+
251+ const expectedCliVersion = toolsInput . replace ( / ^ v / , "" ) ;
252+ t . is ( source . toolsVersion , expectedCliVersion ) ;
253+ t . is ( source [ "cliVersion" ] , expectedCliVersion ) ;
254+ t . is ( source . sourceType , "download" ) ;
255+ if ( source . sourceType === "download" ) {
256+ t . is ( source . compressionMethod , expectedCompressionMethod ) ;
257+ t . true ( source . codeqlURL . endsWith ( `/${ expectedBundleName } ` ) ) ;
258+ t . true (
259+ source . codeqlURL . includes ( `/codeql-bundle-v${ expectedCliVersion } /` ) ,
260+ ) ;
261+ }
262+ } ) ;
263+ } ,
264+ ) ;
265+ }
266+
267+ test . serial (
268+ "getCodeQLSource logs a message when given a bare CLI version number" ,
269+ async ( t ) => {
270+ const loggedMessages : LoggedMessage [ ] = [ ] ;
271+ const logger = getRecordingLogger ( loggedMessages ) ;
272+ const features = createFeatures ( [ ] ) ;
273+
274+ sinon . stub ( process , "platform" ) . value ( "linux" ) ;
275+
276+ await withTmpDir ( async ( tmpDir ) => {
277+ setupActionsVars ( tmpDir , tmpDir ) ;
278+ const source = await setupCodeql . getCodeQLSource (
279+ "v2.20.1" ,
280+ SAMPLE_DEFAULT_CLI_VERSION ,
281+ undefined , // rawLanguages
282+ false , // useOverlayAwareDefaultCliVersion
283+ SAMPLE_DOTCOM_API_DETAILS ,
284+ GitHubVariant . DOTCOM ,
285+ true ,
286+ features ,
287+ logger ,
288+ ) ;
289+
290+ t . is ( source . sourceType , "download" ) ;
291+ t . is ( source . toolsVersion , "2.20.1" ) ;
292+
293+ checkExpectedLogMessages ( t , loggedMessages , [
294+ "'tools: v2.20.1' was requested, so using CodeQL version 2.20.1." ,
295+ ] ) ;
296+ } ) ;
297+ } ,
298+ ) ;
299+
300+ test . serial (
301+ "getCodeQLSource still resolves a local tarball path when the path looks like a version-ish string" ,
302+ async ( t ) => {
303+ const features = createFeatures ( [ ] ) ;
304+
305+ await withTmpDir ( async ( tmpDir ) => {
306+ setupActionsVars ( tmpDir , tmpDir ) ;
307+ const localPath = "/path/to/codeql-bundle-2.20.1.tar.gz" ;
308+ const source = await setupCodeql . getCodeQLSource (
309+ localPath ,
310+ SAMPLE_DEFAULT_CLI_VERSION ,
311+ undefined , // rawLanguages
312+ false , // useOverlayAwareDefaultCliVersion
313+ SAMPLE_DOTCOM_API_DETAILS ,
314+ GitHubVariant . DOTCOM ,
315+ false ,
316+ features ,
317+ getRunnerLogger ( true ) ,
318+ ) ;
319+
320+ t . is ( source . sourceType , "local" ) ;
321+ if ( source . sourceType === "local" ) {
322+ t . is ( source . codeqlTarPath , localPath ) ;
323+ t . is ( source . compressionMethod , "gzip" ) ;
324+ }
325+ } ) ;
326+ } ,
327+ ) ;
328+
184329test . serial (
185330 "getCodeQLSource correctly returns bundled CLI version when tools == latest" ,
186331 async ( t ) => {
0 commit comments