From 169bec5d8b1a645e16b675d6b7a5d4cc444eac02 Mon Sep 17 00:00:00 2001 From: daz Date: Fri, 28 Jun 2024 12:39:09 -0600 Subject: [PATCH] Provision latest Gradle for cache-cleanup To cleanup Gradle User Home, a Gradle build must be executed. Newer Gradle versions are able to cleanup the home directories of older versions, but not vice-versa. With this change, the latest version of Gradle is automatically provisioned in order to run Gradle User Home cleanup. This ensures a consistent version of Gradle is used for cleanup, and fixes #33 where Gradle is not pre-installed on a custom runner. --- sources/src/caching/cache-cleaner.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sources/src/caching/cache-cleaner.ts b/sources/src/caching/cache-cleaner.ts index 26c64a7d..8081113c 100644 --- a/sources/src/caching/cache-cleaner.ts +++ b/sources/src/caching/cache-cleaner.ts @@ -1,8 +1,8 @@ import * as core from '@actions/core' -import * as exec from '@actions/exec' import * as glob from '@actions/glob' import fs from 'fs' import path from 'path' +import {provisionAndMaybeExecute} from '../execution/gradle' export class CacheCleaner { private readonly gradleUserHome: string @@ -42,10 +42,16 @@ export class CacheCleaner { ) fs.writeFileSync(path.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}') - const gradleCommand = `gradle -g ${this.gradleUserHome} --no-daemon --build-cache --no-scan --quiet -DGITHUB_DEPENDENCY_GRAPH_ENABLED=false noop` - await exec.exec(gradleCommand, [], { - cwd: cleanupProjectDir - }) + await provisionAndMaybeExecute('current', cleanupProjectDir, [ + '-g', + this.gradleUserHome, + '--quiet', + '--no-daemon', + '--no-scan', + '--build-cache', + '-DGITHUB_DEPENDENCY_GRAPH_ENABLED=false', + 'noop' + ]) } private async ageAllFiles(fileName = '*'): Promise {