From 7da993afd54672851f84590d9af39bfad46461df Mon Sep 17 00:00:00 2001 From: daz Date: Fri, 19 Jul 2024 12:08:14 -0600 Subject: [PATCH 1/3] Add 'which' NPM library --- sources/package-lock.json | 79 ++++++++++++++++++++++++++++++++------- sources/package.json | 10 +++-- 2 files changed, 72 insertions(+), 17 deletions(-) diff --git a/sources/package-lock.json b/sources/package-lock.json index 1ab84ed1..ffc416d6 100644 --- a/sources/package-lock.json +++ b/sources/package-lock.json @@ -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": { diff --git a/sources/package.json b/sources/package.json index ae3f39b4..6f72bd8a 100644 --- a/sources/package.json +++ b/sources/package.json @@ -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" } } From 5d7c18409cb9047ff2e02958b099e3e6059f44d9 Mon Sep 17 00:00:00 2001 From: daz Date: Fri, 19 Jul 2024 12:19:14 -0600 Subject: [PATCH 2/3] 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 d38187bd..0eef4d6b 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 99119220..c7ea7742 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 685ac23a..d0d25c7d 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 +} From 4576973cce442d5a005593f8f6ce3f05dd6498f5 Mon Sep 17 00:00:00 2001 From: daz Date: Fri, 19 Jul 2024 13:33:12 -0600 Subject: [PATCH 3/3] Test provision with more Gradle versions Include Gradle 8.8 since it is the pre-installed version on Windows runners. --- .github/workflows/integ-test-provision-gradle-versions.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integ-test-provision-gradle-versions.yml b/.github/workflows/integ-test-provision-gradle-versions.yml index c7ea7742..0ed63a50 100644 --- a/.github/workflows/integ-test-provision-gradle-versions.yml +++ b/.github/workflows/integ-test-provision-gradle-versions.yml @@ -59,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 @@ -70,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