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

handle .x version syntax

This commit is contained in:
Alif Rachmawadi 2019-08-16 18:59:11 +07:00
parent 9421912880
commit be0241570a
No known key found for this signature in database
GPG key ID: 79DA63C0F3A55BB1
2 changed files with 28 additions and 0 deletions

View file

@ -24,6 +24,7 @@ const tc = __importStar(require("@actions/tool-cache"));
const fs = __importStar(require("fs")); const fs = __importStar(require("fs"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
const restm = __importStar(require("typed-rest-client/RestClient")); const restm = __importStar(require("typed-rest-client/RestClient"));
const semver = __importStar(require("semver"));
const v4_1 = __importDefault(require("uuid/v4")); const v4_1 = __importDefault(require("uuid/v4"));
const exec_1 = require("@actions/exec/lib/exec"); const exec_1 = require("@actions/exec/lib/exec");
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
@ -179,6 +180,14 @@ function getLatestVersion(version, channel) {
if (!storage) { if (!storage) {
throw new Error('unable to get latest version'); throw new Error('unable to get latest version');
} }
if (version.endsWith('.x')) {
const sver = version.slice(0, version.length - 2);
const releases = storage.releases.filter(release => release.version.startsWith(`v${sver}`) && release.channel === channel);
const versions = releases.map(release => release.version.slice(1, release.version.length));
const sortedVersions = versions.sort(semver.rcompare);
core.debug(`latest version of ${version} from channel ${channel} is ${sortedVersions[0]}`);
return sortedVersions[0];
}
const channelVersion = storage.releases.find(release => release.hash === storage.current_release[channel]); const channelVersion = storage.releases.find(release => release.hash === storage.current_release[channel]);
if (!channelVersion) { if (!channelVersion) {
throw new Error(`unable to get latest version from channel ${channel}`); throw new Error(`unable to get latest version from channel ${channel}`);

View file

@ -4,6 +4,7 @@ import * as tc from '@actions/tool-cache';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import * as restm from 'typed-rest-client/RestClient'; import * as restm from 'typed-rest-client/RestClient';
import * as semver from 'semver';
import uuidV4 from 'uuid/v4'; import uuidV4 from 'uuid/v4';
import {exec} from '@actions/exec/lib/exec'; import {exec} from '@actions/exec/lib/exec';
@ -218,6 +219,24 @@ async function getLatestVersion(
throw new Error('unable to get latest version'); throw new Error('unable to get latest version');
} }
if (version.endsWith('.x')) {
const sver = version.slice(0, version.length - 2);
const releases = storage.releases.filter(
release =>
release.version.startsWith(`v${sver}`) && release.channel === channel
);
const versions = releases.map(release =>
release.version.slice(1, release.version.length)
);
const sortedVersions = versions.sort(semver.rcompare);
core.debug(
`latest version of ${version} from channel ${channel} is ${sortedVersions[0]}`
);
return sortedVersions[0];
}
const channelVersion = storage.releases.find( const channelVersion = storage.releases.find(
release => release.hash === storage.current_release[channel] release => release.hash === storage.current_release[channel]
); );