From 048d11febc86efa23f6a494f17e329a32734d917 Mon Sep 17 00:00:00 2001 From: Alif Rachmawadi Date: Wed, 14 Aug 2019 08:04:15 +0700 Subject: [PATCH] semver and channel for cache dir --- __tests__/installer.test.ts | 9 +++++++-- lib/installer.js | 7 +++++-- src/installer.ts | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 87ae70d..45ec791 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -27,7 +27,12 @@ describe('installer tests', () => { it('Downloads flutter', async () => { await installer.getFlutter('1.7.8+hotfix.4', 'stable'); - const sdkDir = path.join(toolDir, 'Flutter', '1.7.8', 'x64'); + const sdkDir = path.join( + toolDir, + 'Flutter', + '1.7.8-hotfix.4-stable', + 'x64' + ); expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true); expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true); @@ -35,7 +40,7 @@ describe('installer tests', () => { it('Downloads flutter from beta channel', async () => { await installer.getFlutter('1.8.3', 'beta'); - const sdkDir = path.join(toolDir, 'Flutter', '1.8.3', 'x64'); + const sdkDir = path.join(toolDir, 'Flutter', '1.8.3-beta', 'x64'); expect(fs.existsSync(`${sdkDir}.complete`)).toBe(true); expect(fs.existsSync(path.join(sdkDir, 'bin'))).toBe(true); diff --git a/lib/installer.js b/lib/installer.js index 0f2ad03..b861ac0 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -46,7 +46,10 @@ if (!tempDirectory) { } function getFlutter(version, channel) { return __awaiter(this, void 0, void 0, function* () { - let toolPath = tc.find('Flutter', version); + // make semver compatible, eg: 1.7.8+hotfix.4 -> 1.7.8-hotfix.4 + const semver = version.replace('+', '-'); + const cleanver = `${semver}-${channel}`; + let toolPath = tc.find('Flutter', cleanver); if (toolPath) { core.debug(`Tool found in cache ${toolPath}`); } @@ -57,7 +60,7 @@ function getFlutter(version, channel) { let tempDir = generateTempDir(); const sdkDir = yield extractDownload(sdkFile, tempDir); core.debug(`Flutter sdk extracted to ${sdkDir}`); - toolPath = yield tc.cacheDir(sdkDir, 'Flutter', version); + toolPath = yield tc.cacheDir(sdkDir, 'Flutter', cleanver); } core.exportVariable('FLUTTER_HOME', toolPath); core.addPath(path.join(toolPath, 'bin')); diff --git a/src/installer.ts b/src/installer.ts index 4cec2b8..9b6f23d 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -32,7 +32,10 @@ export async function getFlutter( version: string, channel: string ): Promise { - let toolPath = tc.find('Flutter', version); + // make semver compatible, eg: 1.7.8+hotfix.4 -> 1.7.8-hotfix.4 + const semver = version.replace('+', '-'); + const cleanver = `${semver}-${channel}`; + let toolPath = tc.find('Flutter', cleanver); if (toolPath) { core.debug(`Tool found in cache ${toolPath}`); @@ -46,7 +49,7 @@ export async function getFlutter( const sdkDir = await extractDownload(sdkFile, tempDir); core.debug(`Flutter sdk extracted to ${sdkDir}`); - toolPath = await tc.cacheDir(sdkDir, 'Flutter', version); + toolPath = await tc.cacheDir(sdkDir, 'Flutter', cleanver); } core.exportVariable('FLUTTER_HOME', toolPath);