get latest release automatically
This commit is contained in:
@@ -23,11 +23,13 @@ const io = __importStar(require("@actions/io"));
|
||||
const tc = __importStar(require("@actions/tool-cache"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const restm = __importStar(require("typed-rest-client/RestClient"));
|
||||
const v4_1 = __importDefault(require("uuid/v4"));
|
||||
const exec_1 = require("@actions/exec/lib/exec");
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
const IS_DARWIN = process.platform === 'darwin';
|
||||
const IS_LINUX = process.platform === 'linux';
|
||||
const storageUrl = 'https://storage.googleapis.com/flutter_infra/releases';
|
||||
let tempDirectory = process.env['RUNNER_TEMP'] || '';
|
||||
if (!tempDirectory) {
|
||||
let baseLocation;
|
||||
@@ -46,9 +48,8 @@ if (!tempDirectory) {
|
||||
}
|
||||
function getFlutter(version, channel) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// make semver compatible, eg: 1.7.8+hotfix.4 -> 1.7.8-hotfix.4
|
||||
const semver = version.replace('+', '-');
|
||||
const cleanver = `${semver}-${channel}`;
|
||||
version = yield determineVersion(version, channel);
|
||||
let cleanver = `${version.replace('+', '-')}-${channel}`;
|
||||
let toolPath = tc.find('flutter', cleanver);
|
||||
if (toolPath) {
|
||||
core.debug(`Tool found in cache ${toolPath}`);
|
||||
@@ -82,7 +83,7 @@ function extName() {
|
||||
function getDownloadInfo(version, channel) {
|
||||
const os = osName();
|
||||
const ext = extName();
|
||||
const url = `https://storage.googleapis.com/flutter_infra/releases/${channel}/${os}/flutter_${os}_v${version}-${channel}.${ext}`;
|
||||
const url = `${storageUrl}/${channel}/${os}/flutter_${os}_v${version}-${channel}.${ext}`;
|
||||
return {
|
||||
version,
|
||||
url
|
||||
@@ -162,3 +163,29 @@ function extractZipDarwin(file, dest) {
|
||||
yield exec_1.exec(`"${unzipPath}"`, [file], { cwd: dest });
|
||||
});
|
||||
}
|
||||
function determineVersion(version, channel) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (version.endsWith('.x') || version === '') {
|
||||
return yield getLatestVersion(version, channel);
|
||||
}
|
||||
return version;
|
||||
});
|
||||
}
|
||||
function getLatestVersion(version, channel) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const releasesUrl = `${storageUrl}/releases_${osName()}.json`;
|
||||
const rest = new restm.RestClient('setup-go');
|
||||
const storage = (yield rest.get(releasesUrl)).result;
|
||||
if (!storage) {
|
||||
throw new Error('unable to get latest version');
|
||||
}
|
||||
const channelVersion = storage.releases.find(release => release.hash === storage.current_release[channel]);
|
||||
if (!channelVersion) {
|
||||
throw new Error(`unable to get latest version from channel ${channel}`);
|
||||
}
|
||||
let cver = channelVersion.version;
|
||||
cver = cver.slice(1, cver.length);
|
||||
core.debug(`latest version from channel ${channel} is ${cver}`);
|
||||
return cver;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user