From f22ac61fd17919aa0d466862cd22948de222c9b3 Mon Sep 17 00:00:00 2001 From: daz Date: Mon, 11 Nov 2024 14:39:38 -0700 Subject: [PATCH] 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 --- .github/workflows/ci-check-and-unit-test.yml | 2 +- sources/.tool-versions | 2 +- sources/src/caching/cache-cleaner.ts | 22 +++++++++----------- sources/test/jest/cache-cleanup.test.ts | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci-check-and-unit-test.yml b/.github/workflows/ci-check-and-unit-test.yml index 2fb9d44..fdea756 100644 --- a/.github/workflows/ci-check-and-unit-test.yml +++ b/.github/workflows/ci-check-and-unit-test.yml @@ -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: | diff --git a/sources/.tool-versions b/sources/.tool-versions index 6118058..9698cf0 100644 --- a/sources/.tool-versions +++ b/sources/.tool-versions @@ -1,3 +1,3 @@ # Configuration file for asdf version manager nodejs 20.10.0 -gradle 8.10.2 +gradle 8.11 diff --git a/sources/src/caching/cache-cleaner.ts b/sources/src/caching/cache-cleaner.ts index e23d5ab..4b3f43e 100644 --- a/sources/src/caching/cache-cleaner.ts +++ b/sources/src/caching/cache-cleaner.ts @@ -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) } } diff --git a/sources/test/jest/cache-cleanup.test.ts b/sources/test/jest/cache-cleanup.test.ts index e35b77e..808e602 100644 --- a/sources/test/jest/cache-cleanup.test.ts +++ b/sources/test/jest/cache-cleanup.test.ts @@ -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)