From b175189376edc43a5aaabd29d577751081ad7a3d Mon Sep 17 00:00:00 2001 From: daz Date: Fri, 19 Jul 2024 09:01:03 -0600 Subject: [PATCH 1/2] Download and install Gradle distributions into tmpdir --- sources/src/execution/provision.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sources/src/execution/provision.ts b/sources/src/execution/provision.ts index ae02b90..685ac23 100644 --- a/sources/src/execution/provision.ts +++ b/sources/src/execution/provision.ts @@ -100,7 +100,7 @@ async function installGradleVersion(versionInfo: GradleVersionInfo): Promise { - const installsDir = path.join(os.homedir(), 'gradle-installations/installs') + const installsDir = path.join(getProvisionDir(), 'installs') const installDir = path.join(installsDir, `gradle-${versionInfo.version}`) if (fs.existsSync(installDir)) { core.info(`Gradle installation already exists at ${installDir}`) @@ -119,7 +119,7 @@ async function locateGradleAndDownloadIfRequired(versionInfo: GradleVersionInfo) } async function downloadAndCacheGradleDistribution(versionInfo: GradleVersionInfo): Promise { - const downloadPath = path.join(os.homedir(), `gradle-installations/downloads/gradle-${versionInfo.version}-bin.zip`) + const downloadPath = path.join(getProvisionDir(), `downloads/gradle-${versionInfo.version}-bin.zip`) // TODO: Convert this to a class and inject config const cacheConfig = new CacheConfig() @@ -152,6 +152,11 @@ async function downloadAndCacheGradleDistribution(versionInfo: GradleVersionInfo return downloadPath } +function getProvisionDir(): string { + const tmpDir = process.env['RUNNER_TEMP'] ?? os.tmpdir() + return path.join(tmpDir, `.gradle-actions/gradle-installations`) +} + async function downloadGradleDistribution(versionInfo: GradleVersionInfo, downloadPath: string): Promise { await toolCache.downloadTool(versionInfo.downloadUrl, downloadPath) core.info(`Downloaded ${versionInfo.downloadUrl} to ${downloadPath} (size ${fs.statSync(downloadPath).size})`) From f8aa3ed8b4c5dfe60801d43265e549c3bffb3df5 Mon Sep 17 00:00:00 2001 From: daz Date: Fri, 19 Jul 2024 09:46:45 -0600 Subject: [PATCH 2/2] Use faster D: drive for Gradle User Home on Windows --- sources/src/setup-gradle.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sources/src/setup-gradle.ts b/sources/src/setup-gradle.ts index a877be5..2d2a70e 100644 --- a/sources/src/setup-gradle.ts +++ b/sources/src/setup-gradle.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core' import * as exec from '@actions/exec' +import * as fs from 'fs' import * as path from 'path' import * as os from 'os' import * as caches from './caching/caches' @@ -79,7 +80,22 @@ async function determineGradleUserHome(): Promise { return path.resolve(rootDir, customGradleUserHome) } - return path.resolve(await determineUserHome(), '.gradle') + const defaultGradleUserHome = path.resolve(await determineUserHome(), '.gradle') + // Use the default Gradle User Home if it already exists + if (fs.existsSync(defaultGradleUserHome)) { + core.info(`Gradle User Home already exists at ${defaultGradleUserHome}`) + return defaultGradleUserHome + } + + // Switch Gradle User Home to faster 'D:' drive if possible + if (os.platform() === 'win32' && defaultGradleUserHome.startsWith('C:\\') && fs.existsSync('D:\\a\\')) { + const fasterGradleUserHome = 'D:\\a\\.gradle' + core.info(`Setting GRADLE_USER_HOME to ${fasterGradleUserHome} to leverage (potentially) faster drive.`) + core.exportVariable('GRADLE_USER_HOME', fasterGradleUserHome) + return fasterGradleUserHome + } + + return defaultGradleUserHome } /**