mirror of
https://github.com/gradle/actions.git
synced 2025-11-26 17:09:10 +08:00
Cache validated checksums for later executions
The most common case for validation will be that the wrapper jars are unchanged from a previous workflow run. In this case, we cache the validated wrapper checksums to minimise the work required on a subsequent run. Fixes #172
This commit is contained in:
26
sources/src/wrapper-validation/cache.ts
Normal file
26
sources/src/wrapper-validation/cache.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import {ACTION_METADATA_DIR} from '../configuration'
|
||||
|
||||
export class ChecksumCache {
|
||||
private readonly cacheFile: string
|
||||
|
||||
constructor(gradleUserHome: string) {
|
||||
this.cacheFile = path.resolve(gradleUserHome, ACTION_METADATA_DIR, 'valid-wrappers.json')
|
||||
}
|
||||
|
||||
load(): string[] {
|
||||
// Load previously validated checksums saved in Gradle User Home
|
||||
if (fs.existsSync(this.cacheFile)) {
|
||||
return JSON.parse(fs.readFileSync(this.cacheFile, 'utf-8'))
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
save(checksums: string[]): void {
|
||||
const uniqueChecksums = [...new Set(checksums)]
|
||||
// Save validated checksums to Gradle User Home
|
||||
fs.mkdirSync(path.dirname(this.cacheFile), {recursive: true})
|
||||
fs.writeFileSync(this.cacheFile, JSON.stringify(uniqueChecksums))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user