From 8f6ad7c38338c9f9bbd6265205c4c2245d7709ee Mon Sep 17 00:00:00 2001 From: Peter Leibiger Date: Wed, 28 Apr 2021 20:25:09 +0200 Subject: [PATCH] Export PUB_CACHE if it is not in env Export `PUB_CACHE` if it is not configured before calling the action. This ensures that flutter and dart use the same cache. It also enables other tools to use this official Dart env variable. --- dist/index.js | 7 ++++++- src/installer.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 54d1ac1..f1be568 100644 --- a/dist/index.js +++ b/dist/index.js @@ -123,9 +123,14 @@ function getFlutter(version, channel) { toolPath = yield tc.cacheDir(sdkDir, 'flutter', cleanver); } core.exportVariable('FLUTTER_ROOT', toolPath); + let pubCachePath = process.env['PUB_CACHE'] || ''; + if (!pubCachePath) { + pubCachePath = path.join(toolPath, '.pub-cache'); + core.exportVariable('PUB_CACHE', pubCachePath); + } core.addPath(path.join(toolPath, 'bin')); core.addPath(path.join(toolPath, 'bin', 'cache', 'dart-sdk', 'bin')); - core.addPath(path.join(toolPath, '.pub-cache', 'bin')); + core.addPath(path.join(pubCachePath, 'bin')); if (useMaster) { yield exec.exec('flutter', ['channel', 'master']); yield exec.exec('flutter', ['upgrade']); diff --git a/src/installer.ts b/src/installer.ts index b3f36f5..334a86f 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -46,9 +46,17 @@ export async function getFlutter( } core.exportVariable('FLUTTER_ROOT', toolPath); + + let pubCachePath = process.env['PUB_CACHE'] || ''; + + if (!pubCachePath) { + pubCachePath = path.join(toolPath, '.pub-cache'); + core.exportVariable('PUB_CACHE', pubCachePath); + } + core.addPath(path.join(toolPath, 'bin')); core.addPath(path.join(toolPath, 'bin', 'cache', 'dart-sdk', 'bin')); - core.addPath(path.join(toolPath, '.pub-cache', 'bin')); + core.addPath(path.join(pubCachePath, 'bin')); if (useMaster) { await exec.exec('flutter', ['channel', 'master']);