Skip to content

Commit

Permalink
Use pre-installed Gradle when available (#301)
Browse files Browse the repository at this point in the history
Fixes #270
  • Loading branch information
bigdaz authored Jul 19, 2024
2 parents de6862d + 4576973 commit 4b56f19
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 24 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/integ-test-execution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/integ-test-provision-gradle-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
79 changes: 66 additions & 13 deletions sources/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions sources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
20 changes: 20 additions & 0 deletions sources/src/execution/provision.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -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
}

0 comments on commit 4b56f19

Please # to comment.