mirror of
https://github.com/gradle/actions.git
synced 2026-04-19 18:12:58 +08:00
Add Gradle provisioning for cache cleanup (self-contained)
Restore full Gradle provisioning in the legacy module with all functions copied locally. No cross-package imports from sources/src/. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Generated
+85
-39
@@ -14,7 +14,10 @@
|
|||||||
"@actions/exec": "3.0.0",
|
"@actions/exec": "3.0.0",
|
||||||
"@actions/github": "9.0.0",
|
"@actions/github": "9.0.0",
|
||||||
"@actions/glob": "0.6.1",
|
"@actions/glob": "0.6.1",
|
||||||
"semver": "7.7.4"
|
"@actions/http-client": "4.0.0",
|
||||||
|
"@actions/tool-cache": "4.0.0",
|
||||||
|
"semver": "7.7.4",
|
||||||
|
"which": "6.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"esbuild": "0.27.4",
|
"esbuild": "0.27.4",
|
||||||
@@ -68,6 +71,16 @@
|
|||||||
"minimatch": "^3.0.4"
|
"minimatch": "^3.0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@actions/cache/node_modules/@actions/http-client": {
|
||||||
|
"version": "2.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz",
|
||||||
|
"integrity": "sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"tunnel": "^0.0.6",
|
||||||
|
"undici": "^5.25.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@actions/cache/node_modules/semver": {
|
"node_modules/@actions/cache/node_modules/semver": {
|
||||||
"version": "6.3.1",
|
"version": "6.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
|
||||||
@@ -77,6 +90,18 @@
|
|||||||
"semver": "bin/semver.js"
|
"semver": "bin/semver.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@actions/cache/node_modules/undici": {
|
||||||
|
"version": "5.29.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz",
|
||||||
|
"integrity": "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@fastify/busboy": "^2.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-3.0.0.tgz",
|
||||||
@@ -87,16 +112,6 @@
|
|||||||
"@actions/http-client": "^4.0.0"
|
"@actions/http-client": "^4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/core/node_modules/@actions/http-client": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.0.tgz",
|
|
||||||
"integrity": "sha512-QuwPsgVMsD6qaPD57GLZi9sqzAZCtiJT8kVBCDpLtxhL5MydQ4gS+DrejtZZPdIYyB1e95uCK9Luyds7ybHI3g==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"tunnel": "^0.0.6",
|
|
||||||
"undici": "^6.23.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@actions/exec": {
|
"node_modules/@actions/exec": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-3.0.0.tgz",
|
||||||
@@ -148,25 +163,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/http-client": {
|
"node_modules/@actions/http-client": {
|
||||||
"version": "2.2.3",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.0.tgz",
|
||||||
"integrity": "sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==",
|
"integrity": "sha512-QuwPsgVMsD6qaPD57GLZi9sqzAZCtiJT8kVBCDpLtxhL5MydQ4gS+DrejtZZPdIYyB1e95uCK9Luyds7ybHI3g==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tunnel": "^0.0.6",
|
"tunnel": "^0.0.6",
|
||||||
"undici": "^5.25.4"
|
"undici": "^6.23.0"
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@actions/http-client/node_modules/undici": {
|
|
||||||
"version": "5.29.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.29.0.tgz",
|
|
||||||
"integrity": "sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@fastify/busboy": "^2.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=14.0"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/io": {
|
"node_modules/@actions/io": {
|
||||||
@@ -175,6 +178,25 @@
|
|||||||
"integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==",
|
"integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/@actions/tool-cache": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-L8P9HbXvpvqjZDveb/fdsa55IVC0trfPgQ4ZwGo6r5af6YDVdM9vMGPZ7rgY2fAT9gGj4PSYd6bYlg3p3jD78A==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^3.0.0",
|
||||||
|
"@actions/exec": "^3.0.0",
|
||||||
|
"@actions/http-client": "^4.0.0",
|
||||||
|
"@actions/io": "^3.0.0",
|
||||||
|
"semver": "^7.7.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@actions/tool-cache/node_modules/@actions/io": {
|
||||||
|
"version": "3.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@actions/io/-/io-3.0.2.tgz",
|
||||||
|
"integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@azure/abort-controller": {
|
"node_modules/@azure/abort-controller": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.1.0.tgz",
|
||||||
@@ -1333,6 +1355,29 @@
|
|||||||
"node": ">= 8"
|
"node": ">= 8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/cross-spawn/node_modules/isexe": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
|
"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,
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"isexe": "^2.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"node-which": "bin/node-which"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.4.3",
|
"version": "4.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
|
||||||
@@ -1851,11 +1896,13 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/isexe": {
|
"node_modules/isexe": {
|
||||||
"version": "2.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/isexe/-/isexe-4.0.0.tgz",
|
||||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
"integrity": "sha512-FFUtZMpoZ8RqHS3XeXEmHWLA4thH+ZxCv2lOiPIn1Xc7CxrqhWzNSDzD+/chS/zbYezmiwWLdQC09JdQKmthOw==",
|
||||||
"dev": true,
|
"license": "BlueOak-1.0.0",
|
||||||
"license": "ISC"
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"node_modules/json-stable-stringify": {
|
"node_modules/json-stable-stringify": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
@@ -2363,19 +2410,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/which": {
|
"node_modules/which": {
|
||||||
"version": "2.0.2",
|
"version": "6.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/which/-/which-6.0.1.tgz",
|
||||||
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
|
"integrity": "sha512-oGLe46MIrCRqX7ytPUf66EAYvdeMIZYn3WaocqqKZAxrBpkqHfL/qvTyJ/bTk5+AqHCjXmrv3CEWgy368zhRUg==",
|
||||||
"dev": true,
|
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"isexe": "^2.0.0"
|
"isexe": "^4.0.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"node-which": "bin/node-which"
|
"node-which": "bin/which.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 8"
|
"node": "^20.17.0 || >=22.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/wrappy": {
|
"node_modules/wrappy": {
|
||||||
|
|||||||
@@ -14,7 +14,10 @@
|
|||||||
"@actions/exec": "3.0.0",
|
"@actions/exec": "3.0.0",
|
||||||
"@actions/github": "9.0.0",
|
"@actions/github": "9.0.0",
|
||||||
"@actions/glob": "0.6.1",
|
"@actions/glob": "0.6.1",
|
||||||
"semver": "7.7.4"
|
"@actions/http-client": "4.0.0",
|
||||||
|
"@actions/tool-cache": "4.0.0",
|
||||||
|
"semver": "7.7.4",
|
||||||
|
"which": "6.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"esbuild": "0.27.4",
|
"esbuild": "0.27.4",
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import * as exec from '@actions/exec'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import {BuildResults} from './build-results-adapter'
|
import {BuildResults} from './build-results-adapter'
|
||||||
import {findGradleExecutableForCleanup} from './gradle-utils'
|
import {versionIsAtLeast, provisionGradleWithVersionAtLeast} from './gradle-utils'
|
||||||
|
|
||||||
|
const MINIMUM_CLEANUP_GRADLE_VERSION = '8.11'
|
||||||
|
const DEFAULT_CLEANUP_GRADLE_VERSION = '9.4.1'
|
||||||
|
|
||||||
export class CacheCleaner {
|
export class CacheCleaner {
|
||||||
private readonly gradleUserHome: string
|
private readonly gradleUserHome: string
|
||||||
@@ -23,15 +26,32 @@ export class CacheCleaner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async forceCleanup(buildResults: BuildResults): Promise<void> {
|
async forceCleanup(buildResults: BuildResults): Promise<void> {
|
||||||
const executable = findGradleExecutableForCleanup(buildResults)
|
const executable = await this.gradleExecutableForCleanup(buildResults)
|
||||||
if (!executable) {
|
|
||||||
core.warning('Cache cleanup skipped: no suitable Gradle >= 8.11 found in build results.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const cleanTimestamp = core.getState('clean-timestamp')
|
const cleanTimestamp = core.getState('clean-timestamp')
|
||||||
await this.forceCleanupFilesOlderThan(cleanTimestamp, executable)
|
await this.forceCleanupFilesOlderThan(cleanTimestamp, executable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to use the newest Gradle version that was used to run a build, at least 8.11.
|
||||||
|
*
|
||||||
|
* This will avoid the need to provision a Gradle version for the cleanup when not necessary.
|
||||||
|
*/
|
||||||
|
private async gradleExecutableForCleanup(buildResults: BuildResults): Promise<string> {
|
||||||
|
const preferredVersion = buildResults.highestGradleVersion()
|
||||||
|
if (preferredVersion && versionIsAtLeast(preferredVersion, MINIMUM_CLEANUP_GRADLE_VERSION)) {
|
||||||
|
try {
|
||||||
|
return await provisionGradleWithVersionAtLeast(preferredVersion)
|
||||||
|
} catch (e) {
|
||||||
|
core.info(
|
||||||
|
`Failed to provision Gradle ${preferredVersion} for cache cleanup. Falling back to default version.`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to the default version for cache-cleanup
|
||||||
|
return await provisionGradleWithVersionAtLeast(DEFAULT_CLEANUP_GRADLE_VERSION)
|
||||||
|
}
|
||||||
|
|
||||||
// Visible for testing
|
// Visible for testing
|
||||||
async forceCleanupFilesOlderThan(cleanTimestamp: string, executable: string): Promise<void> {
|
async forceCleanupFilesOlderThan(cleanTimestamp: string, executable: string): Promise<void> {
|
||||||
// Run a dummy Gradle build to trigger cache cleanup
|
// Run a dummy Gradle build to trigger cache cleanup
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
|
import * as os from 'os'
|
||||||
import * as semver from 'semver'
|
import * as semver from 'semver'
|
||||||
import {BuildResults} from './build-results-adapter'
|
import * as httpm from '@actions/http-client'
|
||||||
|
import * as toolCache from '@actions/tool-cache'
|
||||||
|
|
||||||
|
import which from 'which'
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32'
|
const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
const gradleVersionsBaseUrl = 'https://services.gradle.org/versions'
|
||||||
|
|
||||||
class GradleVersion {
|
class GradleVersion {
|
||||||
static PATTERN = /((\d+)(\.\d+)+)(-([a-z]+)-(\w+))?(-(SNAPSHOT|\d{14}([-+]\d{4})?))?/
|
static PATTERN = /((\d+)(\.\d+)+)(-([a-z]+)-(\w+))?(-(SNAPSHOT|\d{14}([-+]\d{4})?))?/
|
||||||
@@ -63,33 +68,96 @@ export function versionIsAtLeast(actualVersion: string, requiredVersion: string)
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapperScriptFilename(): string {
|
function installScriptFilename(): string {
|
||||||
return IS_WINDOWS ? 'gradlew.bat' : 'gradlew'
|
return IS_WINDOWS ? 'gradle.bat' : 'gradle'
|
||||||
|
}
|
||||||
|
|
||||||
|
async function findGradleExecutableOnPath(): Promise<string | null> {
|
||||||
|
return await which('gradle', {nothrow: true})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function determineGradleVersion(gradleExecutable: string): Promise<string | undefined> {
|
||||||
|
const {exec} = await import('@actions/exec')
|
||||||
|
const output = await (await import('@actions/exec')).getExecOutput(gradleExecutable, ['-v'], {silent: true})
|
||||||
|
const regex = /Gradle (\d+\.\d+(\.\d+)?(-.*)?)/
|
||||||
|
return output.stdout.match(regex)?.[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GradleVersionInfo {
|
||||||
|
version: string
|
||||||
|
downloadUrl: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to find a Gradle wrapper script from build results that has Gradle >= 8.11.
|
* Find (or install) a Gradle executable that meets the specified version requirement.
|
||||||
* Returns the full path to the wrapper script, or null if none found.
|
* Checks Gradle on PATH and any candidates first, then downloads if needed.
|
||||||
*/
|
*/
|
||||||
export function findGradleExecutableForCleanup(buildResults: BuildResults): string | null {
|
export async function provisionGradleWithVersionAtLeast(
|
||||||
const preferredVersion = buildResults.highestGradleVersion()
|
minimumVersion: string,
|
||||||
if (!preferredVersion || !versionIsAtLeast(preferredVersion, '8.11')) {
|
candidates: string[] = []
|
||||||
core.info(
|
): Promise<string> {
|
||||||
`No Gradle version >= 8.11 found in build results (highest: ${preferredVersion ?? 'none'}). Cache cleanup will be skipped.`
|
const gradleOnPath = await findGradleExecutableOnPath()
|
||||||
)
|
const allCandidates = gradleOnPath ? [gradleOnPath, ...candidates] : candidates
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find a build result with the highest version that has a wrapper script
|
return core.group(`Provision Gradle >= ${minimumVersion}`, async () => {
|
||||||
for (const result of buildResults.results) {
|
for (const candidate of allCandidates) {
|
||||||
if (versionIsAtLeast(result.gradleVersion, '8.11')) {
|
const candidateVersion = await determineGradleVersion(candidate)
|
||||||
const wrapperScript = path.resolve(result.rootProjectDir, wrapperScriptFilename())
|
if (candidateVersion && versionIsAtLeast(candidateVersion, minimumVersion)) {
|
||||||
if (fs.existsSync(wrapperScript)) {
|
core.info(
|
||||||
return wrapperScript
|
`Gradle version ${candidateVersion} is available at ${candidate} and >= ${minimumVersion}. Not installing.`
|
||||||
|
)
|
||||||
|
return candidate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return locateGradleAndDownloadIfRequired(await gradleRelease(minimumVersion))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function gradleRelease(version: string): Promise<GradleVersionInfo> {
|
||||||
|
const allVersions: GradleVersionInfo[] = JSON.parse(
|
||||||
|
await httpGetString(`${gradleVersionsBaseUrl}/all`)
|
||||||
|
)
|
||||||
|
const versionInfo = allVersions.find(entry => entry.version === version)
|
||||||
|
if (!versionInfo) {
|
||||||
|
throw new Error(`Gradle version ${version} does not exist`)
|
||||||
|
}
|
||||||
|
return versionInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
async function locateGradleAndDownloadIfRequired(versionInfo: GradleVersionInfo): Promise<string> {
|
||||||
|
const installsDir = path.join(getProvisionDir(), 'installs')
|
||||||
|
const installDir = path.join(installsDir, `gradle-${versionInfo.version}`)
|
||||||
|
if (fs.existsSync(installDir)) {
|
||||||
|
core.info(`Gradle installation already exists at ${installDir}`)
|
||||||
|
return executableFrom(installDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info('Could not locate a Gradle >= 8.11 executable for cache cleanup.')
|
const downloadPath = path.join(getProvisionDir(), `downloads/gradle-${versionInfo.version}-bin.zip`)
|
||||||
return null
|
await toolCache.downloadTool(versionInfo.downloadUrl, downloadPath)
|
||||||
|
core.info(`Downloaded ${versionInfo.downloadUrl} to ${downloadPath} (size ${fs.statSync(downloadPath).size})`)
|
||||||
|
|
||||||
|
await toolCache.extractZip(downloadPath, installsDir)
|
||||||
|
core.info(`Extracted Gradle ${versionInfo.version} to ${installDir}`)
|
||||||
|
|
||||||
|
const executable = executableFrom(installDir)
|
||||||
|
fs.chmodSync(executable, '755')
|
||||||
|
core.info(`Provisioned Gradle executable ${executable}`)
|
||||||
|
|
||||||
|
return executable
|
||||||
|
}
|
||||||
|
|
||||||
|
function getProvisionDir(): string {
|
||||||
|
const tmpDir = process.env['RUNNER_TEMP'] ?? os.tmpdir()
|
||||||
|
return path.join(tmpDir, '.gradle-actions/gradle-installations')
|
||||||
|
}
|
||||||
|
|
||||||
|
function executableFrom(installDir: string): string {
|
||||||
|
return path.join(installDir, 'bin', installScriptFilename())
|
||||||
|
}
|
||||||
|
|
||||||
|
async function httpGetString(url: string): Promise<string> {
|
||||||
|
const httpClient = new httpm.HttpClient('gradle/actions')
|
||||||
|
const response = await httpClient.get(url)
|
||||||
|
return response.readBody()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user