Use Gradle 8.11 as the minimum version for cache-cleanup

The cache-cleanup API has changed, so the init-script that worked with
Gradle 8.9 no longer works with 8.11.
We now provision and use Gradle 8.11 for cache cleanup.

This provides a band-aid fix for #417 but that issue will still impact
any build configured to run with Gradle > 8.11
This commit is contained in:
daz 2024-11-11 14:39:38 -07:00 committed by Daz DeBoer
parent 4ec844e551
commit f22ac61fd1
4 changed files with 14 additions and 16 deletions

View file

@ -28,7 +28,7 @@ jobs:
env:
ALLOWED_GRADLE_WRAPPER_CHECKSUMS: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 # Invalid wrapper jar used for testing
with:
gradle-version: "8.10.2"
gradle-version: "8.11"
- name: Check formatting and compile
run: |

View file

@ -1,3 +1,3 @@
# Configuration file for asdf version manager
nodejs 20.10.0
gradle 8.10.2
gradle 8.11

View file

@ -44,19 +44,20 @@ export class CacheCleaner {
settings.caches {
cleanup = Cleanup.ALWAYS
releasedWrappers.removeUnusedEntriesOlderThan.set(cleanupTime)
snapshotWrappers.removeUnusedEntriesOlderThan.set(cleanupTime)
downloadedResources.removeUnusedEntriesOlderThan.set(cleanupTime)
createdResources.removeUnusedEntriesOlderThan.set(cleanupTime)
buildCache.removeUnusedEntriesOlderThan.set(cleanupTime)
releasedWrappers.setRemoveUnusedEntriesOlderThan(cleanupTime)
snapshotWrappers.setRemoveUnusedEntriesOlderThan(cleanupTime)
downloadedResources.setRemoveUnusedEntriesOlderThan(cleanupTime)
createdResources.setRemoveUnusedEntriesOlderThan(cleanupTime)
buildCache.setRemoveUnusedEntriesOlderThan(cleanupTime)
}
}
`
)
fs.writeFileSync(path.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}')
// Gradle >= 8.9 required for cache cleanup
const executable = await provisioner.provisionGradleAtLeast('8.9')
// Gradle >= 8.11 required for cache cleanup
// TODO: This is ineffective: we should be using the newest version of Gradle that ran a build, or a newer version if it's available on PATH.
const executable = await provisioner.provisionGradleAtLeast('8.11')
await core.group('Executing Gradle to clean up caches', async () => {
core.info(`Cleaning up caches last used before ${cleanTimestamp}`)
@ -78,11 +79,8 @@ export class CacheCleaner {
'noop'
]
const result = await exec.getExecOutput(executable, args, {
cwd: cleanupProjectDir,
silent: true
await exec.exec(executable, args, {
cwd: cleanupProjectDir
})
core.info(result.stdout)
}
}

View file

@ -53,8 +53,8 @@ test('will cleanup unused gradle versions', async () => {
const transforms3 = path.resolve(gradleUserHome, "caches/transforms-3")
const metadata100 = path.resolve(gradleUserHome, "caches/modules-2/metadata-2.100")
const wrapper802 = path.resolve(gradleUserHome, "wrapper/dists/gradle-8.0.2-bin")
const gradleCurrent = path.resolve(gradleUserHome, "caches/8.10.2")
const metadataCurrent = path.resolve(gradleUserHome, "caches/modules-2/metadata-2.106")
const gradleCurrent = path.resolve(gradleUserHome, "caches/8.11")
const metadataCurrent = path.resolve(gradleUserHome, "caches/modules-2/metadata-2.107")
expect(fs.existsSync(gradle802)).toBe(true)
expect(fs.existsSync(transforms3)).toBe(true)