Unverified Commit 514ac344 authored by Daz DeBoer's avatar Daz DeBoer Committed by GitHub
Browse files

Use faster D: drive on windows for Gradle User Home and Gradle downloads (#299)

Fixes #290 
parents 20e923b8 f8aa3ed8
Loading
Loading
Loading
Loading
+7 −2
Changes for sources/src/execution/provision.ts: 7 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ async function installGradleVersion(versionInfo: GradleVersionInfo): Promise<str
}

async function locateGradleAndDownloadIfRequired(versionInfo: GradleVersionInfo): Promise<string> {
    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<string> {
    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<void> {
    await toolCache.downloadTool(versionInfo.downloadUrl, downloadPath)
    core.info(`Downloaded ${versionInfo.downloadUrl} to ${downloadPath} (size ${fs.statSync(downloadPath).size})`)
+17 −1
Changes for sources/src/setup-gradle.ts: 17 added lines, 1 removed line.
Original line number Diff line number Diff line
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<string> {
        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
}

/**