From be0241570a7d35008b6b9b48fbc498dcf7e4212f Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Fri, 16 Aug 2019 18:59:11 +0700 Subject: [PATCH] handle .x version syntax --- lib/installer.js | 9 +++++++++ src/installer.ts | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/installer.js b/lib/installer.js index b8ad76e..0063225 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -24,6 +24,7 @@ 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 semver = __importStar(require("semver")); const v4_1 = __importDefault(require("uuid/v4")); const exec_1 = require("@actions/exec/lib/exec"); const IS_WINDOWS = process.platform === 'win32'; @@ -179,6 +180,14 @@ function getLatestVersion(version, channel) { if (!storage) { 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]); if (!channelVersion) { throw new Error(`unable to get latest version from channel ${channel}`); diff --git a/src/installer.ts b/src/installer.ts index 286bf7c..1eb0748 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -4,6 +4,7 @@ import * as tc from '@actions/tool-cache'; import * as fs from 'fs'; import * as path from 'path'; import * as restm from 'typed-rest-client/RestClient'; +import * as semver from 'semver'; import uuidV4 from 'uuid/v4'; import {exec} from '@actions/exec/lib/exec'; @@ -218,6 +219,24 @@ async function getLatestVersion( 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] );