1
0
Fork 0
mirror of https://github.com/subosito/flutter-action.git synced 2024-08-16 10:19:50 +02:00

add any channel

This commit is contained in:
Dmitry Shibanov 2020-11-23 16:11:57 +03:00
parent d141f1640a
commit d8b5280c4b
3 changed files with 75 additions and 15 deletions

View file

@ -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');
});
});
});

View file

@ -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);

View file

@ -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<IFlutterData> {
const storage = await getReleases(platform);
if (version === '') {
@ -73,11 +80,11 @@ async function getReleases(platform: string): Promise<IFlutterStorage> {
async function getLatestVersion(
storage: IFlutterStorage,
channel: string
): Promise<{version: string; rawVersion: string; downloadUrl: string}> {
): Promise<IFlutterData> {
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<IFlutterData> {
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<IFlutterData> {
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 {