Unverified Commit 5d7c1840 authored by daz's avatar daz
Browse files

Use pre-installed Gradle when version matches

By executing Gradle on the PATH, we can avoid downloading and installing
a Gradle version that is already available on the runner.

Fixes #270
parent 7da993af
Loading
Loading
Loading
Loading
−3
Changes for .github/workflows/integ-test-execution.yml: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -24,9 +24,6 @@ jobs:
      fail-fast: false
      matrix:
        os: ${{fromJSON(inputs.runner-os)}}
        include:
          - os: windows-latest
            script-suffix: '.bat'
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout sources
−3
Changes for .github/workflows/integ-test-provision-gradle-versions.yml: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -25,9 +25,6 @@ jobs:
      fail-fast: false
      matrix:
        os: ${{fromJSON(inputs.runner-os)}}
        include:
          - os: windows-latest
            script-suffix: '.bat'
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout sources
+20
Changes for sources/src/execution/provision.ts: 20 added lines, 0 removed lines.
Original line number Diff line number Diff line
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import which from 'which'
import * as httpm from '@actions/http-client'
import * as core from '@actions/core'
import * as cache from '@actions/cache'
import * as exec from '@actions/exec'
import * as toolCache from '@actions/tool-cache'

import * as gradlew from './gradlew'
@@ -95,6 +97,12 @@ async function findGradleVersionDeclaration(version: string): Promise<GradleVers

async function installGradleVersion(versionInfo: GradleVersionInfo): Promise<string> {
    return core.group(`Provision Gradle ${versionInfo.version}`, async () => {
        const preInstalledGradle = await findGradleVersionOnPath(versionInfo)
        if (preInstalledGradle !== undefined) {
            core.info(`Gradle version ${versionInfo.version} is already available on PATH. Not installing.`)
            return preInstalledGradle
        }

        return locateGradleAndDownloadIfRequired(versionInfo)
    })
}
@@ -184,3 +192,15 @@ interface GradleVersionInfo {
    version: string
    downloadUrl: string
}

async function findGradleVersionOnPath(versionInfo: GradleVersionInfo): Promise<string | undefined> {
    const gradleExecutable = await which('gradle', {nothrow: true})
    if (gradleExecutable) {
        const output = await exec.getExecOutput(gradleExecutable, ['-v'], {silent: true})
        if (output.stdout.includes(`Gradle ${versionInfo.version}`)) {
            return gradleExecutable
        }
    }

    return undefined
}