mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-10-19 04:01:15 +08:00
322805e800
This is a pure refactor, moving from a separate .cache file per bundle to a single cache-metadata.json file describing all bundles. Instead of storing cache metadata in a separate .cache file per artifact bundle, all of the metadata is now stored in a single `.json` file. This will make it easier to implement more flexible artifact-caching strategies, such as caching each wrapper zip separately. * Always include cache protocol version in cache key * Store all cache metadata in a single JSON file * Rename cache-metadata file and bump protocol version * Polish and documentation
34 lines
984 B
TypeScript
34 lines
984 B
TypeScript
import path from 'path'
|
|
import fs from 'fs'
|
|
import {AbstractCache} from './cache-base'
|
|
|
|
// TODO: Maybe allow the user to override / tweak this set
|
|
const PATHS_TO_CACHE = [
|
|
'configuration-cache' // Only configuration-cache is stored at present
|
|
]
|
|
|
|
/**
|
|
* A simple cache that saves and restores the '.gradle/configuration-cache' directory in the project root.
|
|
*/
|
|
export class ProjectDotGradleCache extends AbstractCache {
|
|
private rootDir: string
|
|
constructor(rootDir: string) {
|
|
super('project', 'Project configuration cache')
|
|
this.rootDir = rootDir
|
|
}
|
|
|
|
protected cacheOutputExists(): boolean {
|
|
const dir = this.getProjectDotGradleDir()
|
|
return fs.existsSync(dir)
|
|
}
|
|
|
|
protected getCachePath(): string[] {
|
|
const dir = this.getProjectDotGradleDir()
|
|
return PATHS_TO_CACHE.map(x => path.resolve(dir, x))
|
|
}
|
|
|
|
private getProjectDotGradleDir(): string {
|
|
return path.resolve(this.rootDir, '.gradle')
|
|
}
|
|
}
|