gradle-build-action/src/caches.ts
Daz DeBoer 6d1455a33e
Tidy-up caching code
- Extracted common code for Gradle User Home and Project .gradle caches
  into abstract supertype.
- Improve error handling by checking error types
2021-09-07 15:17:39 -06:00

33 lines
1.0 KiB
TypeScript

import {GradleUserHomeCache} from './cache-gradle-user-home'
import {ProjectDotGradleCache} from './cache-project-dot-gradle'
import * as core from '@actions/core'
import {isCacheReadEnabled, isCacheSaveEnabled} from './cache-utils'
const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'
export async function restore(buildRootDirectory: string): Promise<void> {
if (!isCacheReadEnabled('gradle')) {
core.debug('Cache read disabled')
return
}
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> {
if (!isCacheSaveEnabled('gradle')) {
core.debug('Cache save disabled')
return
}
core.startGroup('Caching Gradle state')
const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
new GradleUserHomeCache().save()
new ProjectDotGradleCache(buildRootDirectory).save()
core.endGroup()
}