@@ -298,80 +298,71 @@ for (const {
298298 } ) ;
299299}
300300
301- for ( const { isCached, tagName, toolcacheCliVersion } of [
301+ for ( const { githubReleases, toolcacheVersion } of [
302+ // Test that we use the tools from the toolcache when `SAMPLE_DEFAULT_CLI_VERSION` is requested
303+ // and `SAMPLE_DEFAULT_CLI_VERSION-` is in the toolcache.
302304 {
303- isCached : true ,
304- tagName : "codeql-bundle-20230101" ,
305- toolcacheCliVersion : SAMPLE_DEFAULT_CLI_VERSION . cliVersion ,
305+ toolcacheVersion : SAMPLE_DEFAULT_CLI_VERSION . cliVersion ,
306306 } ,
307307 {
308- isCached : true ,
309- // By leaving toolcacheCliVersion undefined, the bundle will be installed
310- // into the toolcache as `${SAMPLE_DEFAULT_CLI_VERSION.cliVersion}-20230101`.
311- // This lets us test that `x.y.z-yyyymmdd` toolcache versions are used if an
312- // `x.y.z` version isn't in the toolcache.
313- tagName : `codeql-bundle-${ SAMPLE_DEFAULT_CLI_VERSION . cliVersion } -20230101` ,
308+ githubReleases : {
309+ "codeql-bundle-20230101" : `cli-version-${ SAMPLE_DEFAULT_CLI_VERSION . cliVersion } .txt` ,
310+ } ,
311+ toolcacheVersion : "0.0.0-20230101" ,
314312 } ,
315313 {
316- isCached : false ,
317- tagName : "codeql-bundle-20230101" ,
314+ toolcacheVersion : `${ SAMPLE_DEFAULT_CLI_VERSION . cliVersion } -20230101` ,
318315 } ,
319316] ) {
320- test ( `uses default version on Dotcom when default version bundle ${ tagName } is ${
321- isCached ? "" : "not "
322- } cached`, async ( t ) => {
323- await util . withTmpDir ( async ( tmpDir ) => {
324- setupActionsVars ( tmpDir , tmpDir ) ;
325-
326- if ( isCached ) {
327- await installIntoToolcache ( {
328- cliVersion : toolcacheCliVersion ,
329- tagName,
330- isPinned : true ,
331- tmpDir,
332- } ) ;
333- } else {
334- mockDownloadApi ( {
335- tagName,
336- } ) ;
337- sinon . stub ( api , "getApiClient" ) . value ( ( ) => ( {
338- repos : {
339- listReleases : sinon . stub ( ) . resolves ( undefined ) ,
340- } ,
341- paginate : sinon . stub ( ) . resolves ( [
342- {
343- assets : [
344- {
345- name : "cli-version-2.0.0.txt" ,
346- } ,
347- ] ,
348- tag_name : tagName ,
317+ test (
318+ `uses tools from toolcache when ${ SAMPLE_DEFAULT_CLI_VERSION . cliVersion } is requested and ` +
319+ `${ toolcacheVersion } is installed` ,
320+ async ( t ) => {
321+ await util . withTmpDir ( async ( tmpDir ) => {
322+ setupActionsVars ( tmpDir , tmpDir ) ;
323+
324+ sinon
325+ . stub ( toolcache , "find" )
326+ . withArgs ( "CodeQL" , toolcacheVersion )
327+ . returns ( "path/to/cached/codeql" ) ;
328+ sinon . stub ( toolcache , "findAllVersions" ) . returns ( [ toolcacheVersion ] ) ;
329+
330+ if ( githubReleases ) {
331+ sinon . stub ( api , "getApiClient" ) . value ( ( ) => ( {
332+ repos : {
333+ listReleases : sinon . stub ( ) . resolves ( undefined ) ,
349334 } ,
350- ] ) ,
351- } ) ) ;
352- }
353-
354- const result = await codeql . setupCodeQL (
355- undefined ,
356- sampleApiDetails ,
357- tmpDir ,
358- util . GitHubVariant . DOTCOM ,
359- false ,
360- SAMPLE_DEFAULT_CLI_VERSION ,
361- getRunnerLogger ( true ) ,
362- false
363- ) ;
364- t . is ( result . toolsVersion , SAMPLE_DEFAULT_CLI_VERSION . cliVersion ) ;
365-
366- if ( isCached ) {
335+ paginate : sinon . stub ( ) . resolves (
336+ Object . entries ( githubReleases ) . map (
337+ ( [ releaseTagName , cliVersionMarkerFile ] ) => ( {
338+ assets : [
339+ {
340+ name : cliVersionMarkerFile ,
341+ } ,
342+ ] ,
343+ tag_name : releaseTagName ,
344+ } )
345+ )
346+ ) ,
347+ } ) ) ;
348+ }
349+
350+ const result = await codeql . setupCodeQL (
351+ undefined ,
352+ sampleApiDetails ,
353+ tmpDir ,
354+ util . GitHubVariant . DOTCOM ,
355+ false ,
356+ SAMPLE_DEFAULT_CLI_VERSION ,
357+ getRunnerLogger ( true ) ,
358+ false
359+ ) ;
360+ t . is ( result . toolsVersion , SAMPLE_DEFAULT_CLI_VERSION . cliVersion ) ;
367361 t . is ( result . toolsSource , ToolsSource . Toolcache ) ;
368362 t . is ( result . toolsDownloadDurationMs , undefined ) ;
369- } else {
370- t . is ( result . toolsSource , ToolsSource . Download ) ;
371- t . is ( typeof result . toolsDownloadDurationMs , "number" ) ;
372- }
373- } ) ;
374- } ) ;
363+ } ) ;
364+ }
365+ ) ;
375366}
376367
377368for ( const variant of [ util . GitHubVariant . GHAE , util . GitHubVariant . GHES ] ) {
0 commit comments