Restore/save configuration-cache data in first action

Previously, the action was restoring/saving the configuration-cache data for each
step that applied the action. In order to support Gradle invocations that are _not_
managed by the action, the configuration-cache restore is now performed in the initial
action step, and save is performed in the final post-action step.

The build root directories are recorded for each invocation via an init script.
This commit is contained in:
Daz DeBoer 2021-12-07 16:52:53 -07:00
parent 1041604f29
commit e1f84aa44d
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
6 changed files with 107 additions and 75 deletions

View file

@ -1,5 +1,6 @@
import * as core from '@actions/core'
import * as path from 'path'
import * as os from 'os'
import {parseArgsStringToArgv} from 'string-argv'
import * as caches from './caches'
@ -14,8 +15,9 @@ export async function run(): Promise<void> {
try {
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || ''
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory)
const gradleUserHome = determineGradleUserHome(buildRootDirectory)
await caches.restore(buildRootDirectory)
await caches.restore(gradleUserHome)
const args: string[] = parseCommandLineArguments()
@ -63,6 +65,15 @@ function resolveBuildRootDirectory(baseDirectory: string): string {
return resolvedBuildRootDirectory
}
function determineGradleUserHome(rootDir: string): string {
const customGradleUserHome = process.env['GRADLE_USER_HOME']
if (customGradleUserHome) {
return path.resolve(rootDir, customGradleUserHome)
}
return path.resolve(os.homedir(), '.gradle')
}
function parseCommandLineArguments(): string[] {
const input = core.getInput('arguments')
return parseArgsStringToArgv(input)