2021-09-06 13:16:08 -04:00
|
|
|
import {GradleUserHomeCache} from './cache-gradle-user-home'
|
|
|
|
import {ProjectDotGradleCache} from './cache-project-dot-gradle'
|
2021-08-20 15:01:43 -04:00
|
|
|
import * as core from '@actions/core'
|
2021-09-12 16:26:38 -04:00
|
|
|
import {isCacheDisabled, isCacheReadOnly} from './cache-utils'
|
2021-08-20 15:01:43 -04:00
|
|
|
|
|
|
|
const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'
|
|
|
|
|
|
|
|
export async function restore(buildRootDirectory: string): Promise<void> {
|
2021-09-12 16:26:38 -04:00
|
|
|
if (isCacheDisabled()) {
|
2021-09-05 21:55:49 -04:00
|
|
|
core.debug('Cache read disabled')
|
|
|
|
return
|
|
|
|
}
|
2021-09-03 13:25:55 -04:00
|
|
|
|
2021-09-06 15:23:36 -04:00
|
|
|
await core.group('Restore Gradle state from cache', async () => {
|
|
|
|
core.saveState(BUILD_ROOT_DIR, buildRootDirectory)
|
|
|
|
return Promise.all([
|
|
|
|
new GradleUserHomeCache().restore(),
|
|
|
|
new ProjectDotGradleCache(buildRootDirectory).restore()
|
|
|
|
])
|
|
|
|
})
|
2021-08-20 15:01:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function save(): Promise<void> {
|
2021-09-12 16:26:38 -04:00
|
|
|
if (isCacheReadOnly()) {
|
|
|
|
core.debug('Cache is read-only: not saving cache entry')
|
2021-09-05 21:55:49 -04:00
|
|
|
return
|
|
|
|
}
|
2021-09-03 13:25:55 -04:00
|
|
|
|
2021-09-06 15:23:36 -04:00
|
|
|
await core.group('Caching Gradle state', async () => {
|
|
|
|
const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
|
|
|
|
return Promise.all([
|
|
|
|
new GradleUserHomeCache().save(),
|
|
|
|
new ProjectDotGradleCache(buildRootDirectory).save()
|
|
|
|
])
|
|
|
|
})
|
2021-08-20 15:01:43 -04:00
|
|
|
}
|