gradle-build-action/src/caches.ts

33 lines
1 KiB
TypeScript
Raw Normal View History

import {GradleUserHomeCache} from './cache-gradle-user-home'
import {ProjectDotGradleCache} from './cache-project-dot-gradle'
import * as core from '@actions/core'
2021-09-05 21:55:49 -04:00
import {isCacheReadEnabled, isCacheSaveEnabled} from './cache-utils'
const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'
export async function restore(buildRootDirectory: string): Promise<void> {
2021-09-05 21:55:49 -04:00
if (!isCacheReadEnabled('gradle')) {
core.debug('Cache read disabled')
return
}
2021-09-05 21:55:49 -04:00
core.startGroup('Restore Gradle state from cache')
core.saveState(BUILD_ROOT_DIR, buildRootDirectory)
new GradleUserHomeCache().restore()
new ProjectDotGradleCache(buildRootDirectory).restore()
core.endGroup()
}
export async function save(): Promise<void> {
2021-09-05 21:55:49 -04:00
if (!isCacheSaveEnabled('gradle')) {
core.debug('Cache save disabled')
return
}
2021-09-05 21:55:49 -04:00
core.startGroup('Caching Gradle state')
const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
new GradleUserHomeCache().save()
new ProjectDotGradleCache(buildRootDirectory).save()
core.endGroup()
}