-
Notifications
You must be signed in to change notification settings - Fork 226
Provide option to point ReleasesApiConsumer at nightly builds repo #3127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
66c0714
0360bf2
69dea08
ba2f44b
c7e2d69
4140303
37b2e42
e565032
c423505
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,16 @@ const DEFAULT_DISTRIBUTION_OWNER_NAME = "github"; | |
| */ | ||
| const DEFAULT_DISTRIBUTION_REPOSITORY_NAME = "codeql-cli-binaries"; | ||
|
|
||
| /** | ||
| * Owner name of the nightly version of the extension-managed distribution on GitHub. | ||
| */ | ||
| const NIGHTLY_DISTRIBUTION_OWNER_NAME = "dsp-testing"; | ||
|
|
||
| /** | ||
| * Repository name of the nightly version of the extension-managed distribution on GitHub. | ||
| */ | ||
| const NIGHTLY_DISTRIBUTION_REPOSITORY_NAME = "codeql-cli-nightlies"; | ||
|
|
||
| /** | ||
| * Range of versions of the CLI that are compatible with the extension. | ||
| * | ||
|
|
@@ -443,9 +453,18 @@ class ExtensionSpecificDistributionManager { | |
| void extLogger.log( | ||
| `Searching for latest release including ${requiredAssetName}.`, | ||
| ); | ||
|
|
||
| const versionRange = this.usingNightlyReleases | ||
| ? undefined | ||
| : this.versionRange; | ||
| const orderBySemver = !this.usingNightlyReleases; | ||
| const includePrerelease = | ||
| this.usingNightlyReleases || this.config.includePrerelease; | ||
|
|
||
| return this.createReleasesApiConsumer().getLatestRelease( | ||
| this.versionRange, | ||
| this.config.includePrerelease, | ||
| versionRange, | ||
| orderBySemver, | ||
| includePrerelease, | ||
| (release) => { | ||
| // v2.12.3 was released with a bug that causes the extension to fail | ||
| // so we force the extension to ignore it. | ||
|
|
@@ -475,19 +494,40 @@ class ExtensionSpecificDistributionManager { | |
| } | ||
|
|
||
| private createReleasesApiConsumer(): ReleasesApiConsumer { | ||
| const ownerName = this.config.ownerName | ||
| ? this.config.ownerName | ||
| : DEFAULT_DISTRIBUTION_OWNER_NAME; | ||
| const repositoryName = this.config.repositoryName | ||
| ? this.config.repositoryName | ||
| : DEFAULT_DISTRIBUTION_REPOSITORY_NAME; | ||
| return new ReleasesApiConsumer( | ||
| ownerName, | ||
| repositoryName, | ||
| this.distributionOwnerName, | ||
| this.distributionRepositoryName, | ||
| this.config.personalAccessToken, | ||
| ); | ||
| } | ||
|
|
||
| private get distributionOwnerName(): string { | ||
| if (this.config.ownerName) { | ||
| return this.config.ownerName; | ||
| } else if (this.config.channel === "nightly") { | ||
| return NIGHTLY_DISTRIBUTION_OWNER_NAME; | ||
| } else { | ||
| return DEFAULT_DISTRIBUTION_OWNER_NAME; | ||
| } | ||
| } | ||
|
|
||
| private get distributionRepositoryName(): string { | ||
| if (this.config.repositoryName) { | ||
| return this.config.repositoryName; | ||
| } else if (this.config.channel === "nightly") { | ||
| return NIGHTLY_DISTRIBUTION_REPOSITORY_NAME; | ||
| } else { | ||
| return DEFAULT_DISTRIBUTION_REPOSITORY_NAME; | ||
| } | ||
| } | ||
|
|
||
| private get usingNightlyReleases(): boolean { | ||
| return ( | ||
| this.distributionOwnerName === NIGHTLY_DISTRIBUTION_OWNER_NAME && | ||
| this.distributionRepositoryName === NIGHTLY_DISTRIBUTION_REPOSITORY_NAME | ||
| ); | ||
| } | ||
|
|
||
| private async bumpDistributionFolderIndex(): Promise<void> { | ||
| const index = this.extensionContext.globalState.get( | ||
| ExtensionSpecificDistributionManager._currentDistributionFolderIndexStateKey, | ||
|
|
@@ -560,7 +600,8 @@ export class ReleasesApiConsumer { | |
| } | ||
|
|
||
| public async getLatestRelease( | ||
| versionRange: semver.Range, | ||
| versionRange: semver.Range | undefined, | ||
| orderBySemver = true, | ||
| includePrerelease = false, | ||
| additionalCompatibilityCheck?: (release: GithubRelease) => boolean, | ||
| ): Promise<Release> { | ||
|
|
@@ -573,12 +614,14 @@ export class ReleasesApiConsumer { | |
| return false; | ||
| } | ||
|
|
||
| const version = semver.parse(release.tag_name); | ||
| if ( | ||
| version === null || | ||
| !semver.satisfies(version, versionRange, { includePrerelease }) | ||
| ) { | ||
| return false; | ||
| if (versionRange !== undefined) { | ||
| const version = semver.parse(release.tag_name); | ||
| if ( | ||
| version === null || | ||
| !semver.satisfies(version, versionRange, { includePrerelease }) | ||
| ) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
|
|
@@ -587,10 +630,9 @@ export class ReleasesApiConsumer { | |
| }); | ||
| // Tag names must all be parsable to semvers due to the previous filtering step. | ||
| const latestRelease = compatibleReleases.sort((a, b) => { | ||
| const versionComparison = semver.compare( | ||
| semver.parse(b.tag_name)!, | ||
| semver.parse(a.tag_name)!, | ||
| ); | ||
| const versionComparison = orderBySemver | ||
| ? semver.compare(semver.parse(b.tag_name)!, semver.parse(a.tag_name)!) | ||
| : b.id - a.id; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure about whether to order based on I also wondered about passing in a comparison function instead this |
||
| if (versionComparison !== 0) { | ||
| return versionComparison; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.