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

@ -4,6 +4,7 @@ import * as crypto from 'crypto'
import * as path from 'path'
import * as fs from 'fs'
const JOB_CONTEXT_PARAMETER = 'workflow-job-context'
const CACHE_DISABLED_PARAMETER = 'cache-disabled'
const CACHE_READONLY_PARAMETER = 'cache-read-only'
const CACHE_DEBUG_VAR = 'GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED'
@ -26,6 +27,17 @@ export function getCacheKeyPrefix(): string {
return process.env[CACHE_PREFIX_VAR] || ''
}
export function determineJobContext(): string {
// By default, we hash the full `matrix` data for the run, to uniquely identify this job invocation
// The only way we can obtain the `matrix` data is via the `workflow-job-context` parameter in action.yml.
const workflowJobContext = core.getInput(JOB_CONTEXT_PARAMETER)
return hashStrings([workflowJobContext])
}
export function hashFileNames(fileNames: string[]): string {
return hashStrings(fileNames.map(x => x.replace(new RegExp(`\\${path.sep}`, 'g'), '/')))
}
export function hashStrings(values: string[]): string {
const hash = crypto.createHash('md5')
for (const value of values) {
@ -34,10 +46,6 @@ export function hashStrings(values: string[]): string {
return hash.digest('hex')
}
export function hashFileNames(fileNames: string[]): string {
return hashStrings(fileNames.map(x => x.replace(new RegExp(`\\${path.sep}`, 'g'), '/')))
}
export function handleCacheFailure(error: unknown, message: string): void {
if (error instanceof cache.ValidationError) {
// Fail on cache validation errors