Skip to content

Commit

Permalink
Use Gradle 8.11 as the minimum version for cache-cleanup
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bigdaz committed Nov 12, 2024
1 parent 4ec844e commit f22ac61
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-check-and-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion sources/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Configuration file for asdf version manager
nodejs 20.10.0
gradle 8.10.2
gradle 8.11
22 changes: 10 additions & 12 deletions sources/src/caching/cache-cleaner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand All @@ -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)
}
}
4 changes: 2 additions & 2 deletions sources/test/jest/cache-cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f22ac61

Please sign in to comment.