From 5d7c18409cb9047ff2e02958b099e3e6059f44d9 Mon Sep 17 00:00:00 2001 From: daz Date: Fri, 19 Jul 2024 12:19:14 -0600 Subject: [PATCH] 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 --- .github/workflows/integ-test-execution.yml | 3 --- .../integ-test-provision-gradle-versions.yml | 3 --- sources/src/execution/provision.ts | 20 +++++++++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/integ-test-execution.yml b/.github/workflows/integ-test-execution.yml index d38187b..0eef4d6 100644 --- a/.github/workflows/integ-test-execution.yml +++ b/.github/workflows/integ-test-execution.yml @@ -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 diff --git a/.github/workflows/integ-test-provision-gradle-versions.yml b/.github/workflows/integ-test-provision-gradle-versions.yml index 9911922..c7ea774 100644 --- a/.github/workflows/integ-test-provision-gradle-versions.yml +++ b/.github/workflows/integ-test-provision-gradle-versions.yml @@ -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 diff --git a/sources/src/execution/provision.ts b/sources/src/execution/provision.ts index 685ac23..d0d25c7 100644 --- a/sources/src/execution/provision.ts +++ b/sources/src/execution/provision.ts @@ -1,9 +1,11 @@ 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 { 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 { + 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 +}