Use pre-installed Gradle when available (#301)

Fixes #270
This commit is contained in:
Daz DeBoer 2024-07-19 14:13:59 -06:00 committed by GitHub
commit 4b56f19bda
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 96 additions and 24 deletions

View file

@ -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

View file

@ -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
@ -62,6 +59,9 @@ jobs:
uses: ./setup-gradle
with:
gradle-version: current
- name: Test use current
working-directory: .github/workflow-samples/no-wrapper
run: gradle help
- name: Check current version output parameter
if: ${{ !startsWith(steps.gradle-current.outputs.gradle-version , '8.') }}
uses: actions/github-script@v7
@ -73,7 +73,7 @@ jobs:
strategy:
fail-fast: false
matrix:
gradle: [7.3, 6.9, 5.6.4, 4.10.3, 3.5.1]
gradle: [8.9, 8.8, 7.6.4, 6.9.4, 5.6.4, 4.10.3, 3.5.1] # 8.8 is the latest installed on windows runners
os: ${{fromJSON(inputs.runner-os)}}
include:
- java-version: 11

View file

@ -23,12 +23,14 @@
"semver": "7.6.0",
"string-argv": "0.3.2",
"typed-rest-client": "1.8.11",
"unhomoglyph": "1.0.6"
"unhomoglyph": "1.0.6",
"which": "4.0.0"
},
"devDependencies": {
"@types/jest": "29.5.12",
"@types/node": "20.12.4",
"@types/unzipper": "0.10.9",
"@types/which": "3.0.4",
"@typescript-eslint/parser": "7.5.0",
"@vercel/ncc": "0.38.1",
"eslint": "8.57.0",
@ -2215,6 +2217,12 @@
"@types/node": "*"
}
},
"node_modules/@types/which": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@types/which/-/which-3.0.4.tgz",
"integrity": "sha512-liyfuo/106JdlgSchJzXEQCVArk0CvevqPote8F8HgWgJ3dRCcTHgJIsLDuee0kxk/mhbInzIZk3QWSZJ8R+2w==",
"dev": true
},
"node_modules/@types/yargs": {
"version": "17.0.23",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.23.tgz",
@ -3694,6 +3702,21 @@
"node": ">= 8"
}
},
"node_modules/cross-spawn/node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"dev": true,
"dependencies": {
"isexe": "^2.0.0"
},
"bin": {
"node-which": "bin/node-which"
},
"engines": {
"node": ">= 8"
}
},
"node_modules/crypto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz",
@ -8885,18 +8908,17 @@
}
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"dev": true,
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz",
"integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==",
"dependencies": {
"isexe": "^2.0.0"
"isexe": "^3.1.1"
},
"bin": {
"node-which": "bin/node-which"
"node-which": "bin/which.js"
},
"engines": {
"node": ">= 8"
"node": "^16.13.0 || >=18.0.0"
}
},
"node_modules/which-boxed-primitive": {
@ -8949,6 +8971,14 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/which/node_modules/isexe": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.1.tgz",
"integrity": "sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ==",
"engines": {
"node": ">=16"
}
},
"node_modules/wrap-ansi": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
@ -10875,6 +10905,12 @@
"@types/node": "*"
}
},
"@types/which": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@types/which/-/which-3.0.4.tgz",
"integrity": "sha512-liyfuo/106JdlgSchJzXEQCVArk0CvevqPote8F8HgWgJ3dRCcTHgJIsLDuee0kxk/mhbInzIZk3QWSZJ8R+2w==",
"dev": true
},
"@types/yargs": {
"version": "17.0.23",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.23.tgz",
@ -11882,6 +11918,17 @@
"path-key": "^3.1.0",
"shebang-command": "^2.0.0",
"which": "^2.0.1"
},
"dependencies": {
"which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"dev": true,
"requires": {
"isexe": "^2.0.0"
}
}
}
},
"crypto": {
@ -15700,12 +15747,18 @@
}
},
"which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
"dev": true,
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz",
"integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==",
"requires": {
"isexe": "^2.0.0"
"isexe": "^3.1.1"
},
"dependencies": {
"isexe": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.1.tgz",
"integrity": "sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ=="
}
}
},
"which-boxed-primitive": {

View file

@ -45,12 +45,14 @@
"semver": "7.6.0",
"string-argv": "0.3.2",
"typed-rest-client": "1.8.11",
"unhomoglyph": "1.0.6"
},
"unhomoglyph": "1.0.6",
"which": "4.0.0"
},
"devDependencies": {
"@types/jest": "29.5.12",
"@types/node": "20.12.4",
"@types/unzipper": "0.10.9",
"@types/which": "3.0.4",
"@typescript-eslint/parser": "7.5.0",
"@vercel/ncc": "0.38.1",
"eslint": "8.57.0",
@ -59,11 +61,11 @@
"eslint-plugin-prettier": "5.1.3",
"jest": "29.7.0",
"js-yaml": "4.1.0",
"nock": "13.5.4",
"npm-run-all": "4.1.5",
"patch-package": "8.0.0",
"prettier": "3.2.5",
"ts-jest": "29.1.2",
"typescript": "5.4.3",
"nock": "13.5.4"
"typescript": "5.4.3"
}
}

View file

@ -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<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
}