From d8b5280c4b503d79413892da496c32801faae468 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 23 Nov 2020 16:11:57 +0300 Subject: [PATCH] add any channel --- __tests__/release.test.ts | 28 +++++++++++++++++++++++ src/installer.ts | 14 +++++++++--- src/release.ts | 48 +++++++++++++++++++++++++++++---------- 3 files changed, 75 insertions(+), 15 deletions(-) diff --git a/__tests__/release.test.ts b/__tests__/release.test.ts index d0f2e95..7d71a71 100644 --- a/__tests__/release.test.ts +++ b/__tests__/release.test.ts @@ -113,5 +113,33 @@ describe('release tests', () => { expect(result.rawVersion).toEqual('1.17.0-dev.5.0'); expect(result.downloadUrl).toContain('1.17.0-dev.5.0'); }); + + it('channel: "any", version: "1.17.x"', async () => { + const result = await release.determineVersion('1.17.x', 'any', platform); + + expect(result.version).toEqual('1.17.5'); + expect(result.rawVersion).toEqual('1.17.5'); + expect(result.downloadUrl).toContain('1.17.5'); + }); + + it('channel: "any", version: "1.19.x"', async () => { + const result = await release.determineVersion('1.19.x', 'any', platform); + + expect(result.version).toEqual('1.19.0-5.0.pre'); + expect(result.rawVersion).toEqual('1.19.0-5.0.pre'); + expect(result.downloadUrl).toContain('1.19.0-5.0.pre'); + }); + + it('channel: "any", version: "1.19.0-4.x"', async () => { + const result = await release.determineVersion( + '1.19.0-4.x', + 'any', + platform + ); + + expect(result.version).toEqual('1.19.0-4.3.pre'); + expect(result.rawVersion).toEqual('1.19.0-4.3.pre'); + expect(result.downloadUrl).toContain('1.19.0-4.3.pre'); + }); }); }); diff --git a/src/installer.ts b/src/installer.ts index 85f9e42..2ceeb46 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -13,15 +13,23 @@ export async function getFlutter( const platform = release.getPlatform(); const useMaster = channel == 'master'; - const {version: selected, downloadUrl} = await release.determineVersion( + const { + version: selected, + downloadUrl, + channel: validatedChannel + } = await release.determineVersion( version, useMaster ? 'dev' : channel, platform ); + if (channel !== validatedChannel) { + core.debug(`Channel was identifyed as ${validatedChannel}`); + } + let cleanver = useMaster - ? channel - : `${selected.replace('+', '-')}-${channel}`; + ? validatedChannel + : `${selected.replace('+', '-')}-${validatedChannel}`; let toolPath = tc.find('flutter', cleanver); diff --git a/src/release.ts b/src/release.ts index 4972e82..a7b992c 100644 --- a/src/release.ts +++ b/src/release.ts @@ -5,6 +5,13 @@ import * as semver from 'semver'; export const storageUrl = 'https://storage.googleapis.com/flutter_infra/releases'; +interface IFlutterData { + channel: string; + version: string; + rawVersion: string; + downloadUrl: string; +} + interface IFlutterChannel { [key: string]: string; beta: string; @@ -42,7 +49,7 @@ export async function determineVersion( version: string, channel: string, platform: string -): Promise<{version: string; rawVersion: string; downloadUrl: string}> { +): Promise { const storage = await getReleases(platform); if (version === '') { @@ -73,11 +80,11 @@ async function getReleases(platform: string): Promise { async function getLatestVersion( storage: IFlutterStorage, channel: string -): Promise<{version: string; rawVersion: string; downloadUrl: string}> { +): Promise { const channelVersion = storage.releases.find(release => { return ( release.hash === storage.current_release[channel] && - release.channel == channel + validateChannel(release.channel, channel) ); }); @@ -90,25 +97,34 @@ async function getLatestVersion( core.debug(`latest version from channel ${channel} is ${rver}`); - return { + const flutterData: IFlutterData = { + channel: channelVersion.channel, version: cver, rawVersion: rver, downloadUrl: `${storageUrl}/${channelVersion.archive}` }; + + return flutterData; +} + +function validateChannel(releaseChannel: string, channel: string) { + return releaseChannel === channel || channel === 'any'; } async function getWildcardVersion( storage: IFlutterStorage, channel: string, version: string -): Promise<{version: string; rawVersion: string; downloadUrl: string}> { +): Promise { let sver = version.endsWith('.x') ? version.slice(0, version.length - 2) : version; const releases = storage.releases.filter(release => { - if (release.channel != channel) return false; - return prefixCompare(sver, release.version); + return ( + validateChannel(release.channel, channel) && + prefixCompare(sver, release.version) + ); }); const versions = releases @@ -130,32 +146,40 @@ async function getWildcardVersion( `latest version of ${version} from channel ${channel} is ${release.version}` ); - return { + const flutterData = { + channel: release.channel, version: cver, rawVersion: release.version, downloadUrl: `${storageUrl}/${release.archive}` }; + + return flutterData; } async function getVersion( storage: IFlutterStorage, channel: string, version: string -): Promise<{version: string; rawVersion: string; downloadUrl: string}> { +): Promise { const release = storage.releases.find(release => { - if (release.channel != channel) return false; - return compare(version, release.version); + return ( + validateChannel(release.channel, channel) && + compare(version, release.version) + ); }); if (!release) { return getWildcardVersion(storage, channel, version); } - return { + const flutterData = { + channel: release.channel, version, rawVersion: release.version, downloadUrl: `${storageUrl}/${release.archive}` }; + + return flutterData; } function compare(version: string, releaseVersion: string): boolean {