mirror of
https://github.com/gradle/actions
synced 2024-11-23 18:02:13 +00:00
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
This commit is contained in:
parent
7da993afd5
commit
5d7c18409c
3 changed files with 20 additions and 6 deletions
3
.github/workflows/integ-test-execution.yml
vendored
3
.github/workflows/integ-test-execution.yml
vendored
|
@ -24,9 +24,6 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: ${{fromJSON(inputs.runner-os)}}
|
os: ${{fromJSON(inputs.runner-os)}}
|
||||||
include:
|
|
||||||
- os: windows-latest
|
|
||||||
script-suffix: '.bat'
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
|
|
|
@ -25,9 +25,6 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: ${{fromJSON(inputs.runner-os)}}
|
os: ${{fromJSON(inputs.runner-os)}}
|
||||||
include:
|
|
||||||
- os: windows-latest
|
|
||||||
script-suffix: '.bat'
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
import which from 'which'
|
||||||
import * as httpm from '@actions/http-client'
|
import * as httpm from '@actions/http-client'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as cache from '@actions/cache'
|
import * as cache from '@actions/cache'
|
||||||
|
import * as exec from '@actions/exec'
|
||||||
import * as toolCache from '@actions/tool-cache'
|
import * as toolCache from '@actions/tool-cache'
|
||||||
|
|
||||||
import * as gradlew from './gradlew'
|
import * as gradlew from './gradlew'
|
||||||
|
@ -95,6 +97,12 @@ async function findGradleVersionDeclaration(version: string): Promise<GradleVers
|
||||||
|
|
||||||
async function installGradleVersion(versionInfo: GradleVersionInfo): Promise<string> {
|
async function installGradleVersion(versionInfo: GradleVersionInfo): Promise<string> {
|
||||||
return core.group(`Provision Gradle ${versionInfo.version}`, async () => {
|
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)
|
return locateGradleAndDownloadIfRequired(versionInfo)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -184,3 +192,15 @@ interface GradleVersionInfo {
|
||||||
version: string
|
version: string
|
||||||
downloadUrl: 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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue