Unverified Commit 169bec5d authored by daz's avatar daz
Browse files

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.
parent b9abb7b1
Loading
Loading
Loading
Loading
+11 −5
Changes for sources/src/caching/cache-cleaner.ts: 11 added lines, 5 removed lines.
Original line number Diff line number Diff line
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<void> {