@@ -15,7 +15,10 @@ import * as api from "./api-client";
15
15
// creation scripts. Ensure that any changes to the format of this file are compatible with both of
16
16
// these dependents.
17
17
import * as defaults from "./defaults.json" ;
18
- import { CodeQLDefaultVersionInfo } from "./feature-flags" ;
18
+ import {
19
+ CODEQL_VERSION_BUNDLE_SEMANTICALLY_VERSIONED ,
20
+ CodeQLDefaultVersionInfo ,
21
+ } from "./feature-flags" ;
19
22
import { Logger } from "./logging" ;
20
23
import * as util from "./util" ;
21
24
import { isGoodVersion , wrapError } from "./util" ;
@@ -610,20 +613,12 @@ export async function downloadCodeQL(
610
613
) ;
611
614
}
612
615
613
- // Include both the CLI version and the bundle version in the toolcache version number. That way
614
- // if the user requests the same URL again, we can get it from the cache without having to call
615
- // any of the Releases API.
616
- //
617
- // Special case: If the CLI version is a pre-release or contains build metadata, then cache the
618
- // bundle as `0.0.0-<bundleVersion>` to avoid the bundle being interpreted as containing a stable
619
- // CLI release. In principle, it should be enough to just check that the CLI version isn't a
620
- // pre-release, but the version numbers of CodeQL nightlies have the format `x.y.z+<timestamp>`,
621
- // and we don't want these nightlies to override stable CLI versions in the toolcache.
622
- const toolcacheVersion = maybeCliVersion ?. match ( / ^ [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + $ / )
623
- ? `${ maybeCliVersion } -${ bundleVersion } `
624
- : convertToSemVer ( bundleVersion , logger ) ;
625
-
626
616
logger . debug ( "Caching CodeQL bundle." ) ;
617
+ const toolcacheVersion = getCanonicalToolcacheVersion (
618
+ maybeCliVersion ,
619
+ bundleVersion ,
620
+ logger ,
621
+ ) ;
627
622
const toolcachedBundlePath = await toolcache . cacheDir (
628
623
extractedBundlePath ,
629
624
"CodeQL" ,
@@ -656,6 +651,38 @@ export function getCodeQLURLVersion(url: string): string {
656
651
return match [ 1 ] ;
657
652
}
658
653
654
+ /**
655
+ * Returns the toolcache version number to use to store the bundle with the associated CLI version
656
+ * and bundle version.
657
+ *
658
+ * This is the canonical version number, since toolcaches populated by different versions of the
659
+ * CodeQL Action or different runner image creation scripts may store the bundle using a different
660
+ * version number. Functions like `getCodeQLSource` that fetch the bundle from rather than save the
661
+ * bundle to the toolcache should handle these different version numbers.
662
+ */
663
+ function getCanonicalToolcacheVersion (
664
+ cliVersion : string | undefined ,
665
+ bundleVersion : string ,
666
+ logger : Logger ,
667
+ ) {
668
+ // If the CLI version is a pre-release or contains build metadata, then cache the
669
+ // bundle as `0.0.0-<bundleVersion>` to avoid the bundle being interpreted as containing a stable
670
+ // CLI release. In principle, it should be enough to just check that the CLI version isn't a
671
+ // pre-release, but the version numbers of CodeQL nightlies have the format `x.y.z+<timestamp>`,
672
+ // and we don't want these nightlies to override stable CLI versions in the toolcache.
673
+ if ( ! cliVersion ?. match ( / ^ [ 0 - 9 ] + \. [ 0 - 9 ] + \. [ 0 - 9 ] + $ / ) ) {
674
+ return convertToSemVer ( bundleVersion , logger ) ;
675
+ }
676
+ // If the bundle is semantically versioned, it can be looked up based on just the CLI version
677
+ // number, so version it in the toolcache using just the CLI version number.
678
+ if ( semver . gte ( cliVersion , CODEQL_VERSION_BUNDLE_SEMANTICALLY_VERSIONED ) ) {
679
+ return cliVersion ;
680
+ }
681
+ // Include both the CLI version and the bundle version in the toolcache version number. That way
682
+ // we can find the bundle in the toolcache based on either the CLI version or the bundle version.
683
+ return `${ cliVersion } -${ bundleVersion } ` ;
684
+ }
685
+
659
686
/**
660
687
* Obtains the CodeQL bundle, installs it in the toolcache if appropriate, and extracts it.
661
688
*
0 commit comments