@@ -51,6 +51,16 @@ const DEFAULT_DISTRIBUTION_OWNER_NAME = "github";
5151 */
5252const DEFAULT_DISTRIBUTION_REPOSITORY_NAME = "codeql-cli-binaries" ;
5353
54+ /**
55+ * Owner name of the nightly version of the extension-managed distribution on GitHub.
56+ */
57+ const NIGHTLY_DISTRIBUTION_OWNER_NAME = "dsp-testing" ;
58+
59+ /**
60+ * Repository name of the nightly version of the extension-managed distribution on GitHub.
61+ */
62+ const NIGHTLY_DISTRIBUTION_REPOSITORY_NAME = "codeql-cli-nightlies" ;
63+
5464/**
5565 * Range of versions of the CLI that are compatible with the extension.
5666 *
@@ -453,9 +463,18 @@ class ExtensionSpecificDistributionManager {
453463 void extLogger . log (
454464 `Searching for latest release including ${ requiredAssetName } .` ,
455465 ) ;
466+
467+ const versionRange = this . usingNightlyReleases
468+ ? undefined
469+ : this . versionRange ;
470+ const orderBySemver = ! this . usingNightlyReleases ;
471+ const includePrerelease =
472+ this . usingNightlyReleases || this . config . includePrerelease ;
473+
456474 return this . createReleasesApiConsumer ( ) . getLatestRelease (
457- this . versionRange ,
458- this . config . includePrerelease ,
475+ versionRange ,
476+ orderBySemver ,
477+ includePrerelease ,
459478 ( release ) => {
460479 // v2.12.3 was released with a bug that causes the extension to fail
461480 // so we force the extension to ignore it.
@@ -485,19 +504,40 @@ class ExtensionSpecificDistributionManager {
485504 }
486505
487506 private createReleasesApiConsumer ( ) : ReleasesApiConsumer {
488- const ownerName = this . config . ownerName
489- ? this . config . ownerName
490- : DEFAULT_DISTRIBUTION_OWNER_NAME ;
491- const repositoryName = this . config . repositoryName
492- ? this . config . repositoryName
493- : DEFAULT_DISTRIBUTION_REPOSITORY_NAME ;
494507 return new ReleasesApiConsumer (
495- ownerName ,
496- repositoryName ,
508+ this . distributionOwnerName ,
509+ this . distributionRepositoryName ,
497510 this . config . personalAccessToken ,
498511 ) ;
499512 }
500513
514+ private get distributionOwnerName ( ) : string {
515+ if ( this . config . ownerName ) {
516+ return this . config . ownerName ;
517+ } else if ( this . config . channel === "nightly" ) {
518+ return NIGHTLY_DISTRIBUTION_OWNER_NAME ;
519+ } else {
520+ return DEFAULT_DISTRIBUTION_OWNER_NAME ;
521+ }
522+ }
523+
524+ private get distributionRepositoryName ( ) : string {
525+ if ( this . config . repositoryName ) {
526+ return this . config . repositoryName ;
527+ } else if ( this . config . channel === "nightly" ) {
528+ return NIGHTLY_DISTRIBUTION_REPOSITORY_NAME ;
529+ } else {
530+ return DEFAULT_DISTRIBUTION_REPOSITORY_NAME ;
531+ }
532+ }
533+
534+ private get usingNightlyReleases ( ) : boolean {
535+ return (
536+ this . distributionOwnerName === NIGHTLY_DISTRIBUTION_OWNER_NAME &&
537+ this . distributionRepositoryName === NIGHTLY_DISTRIBUTION_REPOSITORY_NAME
538+ ) ;
539+ }
540+
501541 private async bumpDistributionFolderIndex ( ) : Promise < void > {
502542 const index = this . extensionContext . globalState . get (
503543 ExtensionSpecificDistributionManager . _currentDistributionFolderIndexStateKey ,
@@ -570,7 +610,8 @@ export class ReleasesApiConsumer {
570610 }
571611
572612 public async getLatestRelease (
573- versionRange : semver . Range ,
613+ versionRange : semver . Range | undefined ,
614+ orderBySemver = true ,
574615 includePrerelease = false ,
575616 additionalCompatibilityCheck ?: ( release : GithubRelease ) => boolean ,
576617 ) : Promise < Release > {
@@ -583,12 +624,14 @@ export class ReleasesApiConsumer {
583624 return false ;
584625 }
585626
586- const version = semver . parse ( release . tag_name ) ;
587- if (
588- version === null ||
589- ! semver . satisfies ( version , versionRange , { includePrerelease } )
590- ) {
591- return false ;
627+ if ( versionRange !== undefined ) {
628+ const version = semver . parse ( release . tag_name ) ;
629+ if (
630+ version === null ||
631+ ! semver . satisfies ( version , versionRange , { includePrerelease } )
632+ ) {
633+ return false ;
634+ }
592635 }
593636
594637 return (
@@ -597,10 +640,9 @@ export class ReleasesApiConsumer {
597640 } ) ;
598641 // Tag names must all be parsable to semvers due to the previous filtering step.
599642 const latestRelease = compatibleReleases . sort ( ( a , b ) => {
600- const versionComparison = semver . compare (
601- semver . parse ( b . tag_name ) ! ,
602- semver . parse ( a . tag_name ) ! ,
603- ) ;
643+ const versionComparison = orderBySemver
644+ ? semver . compare ( semver . parse ( b . tag_name ) ! , semver . parse ( a . tag_name ) ! )
645+ : b . id - a . id ;
604646 if ( versionComparison !== 0 ) {
605647 return versionComparison ;
606648 }
0 commit comments