mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-05 07:46:11 +02:00
Consolidate cache-enabled options
This commit is contained in:
parent
777a6fc967
commit
4d37378696
5 changed files with 26 additions and 49 deletions
|
@ -4,13 +4,8 @@ import os from 'os'
|
|||
|
||||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
import {
|
||||
generateCacheKey,
|
||||
isCacheReadEnabled,
|
||||
isCacheSaveEnabled
|
||||
} from './cache-utils'
|
||||
import {generateCacheKey} from './cache-utils'
|
||||
|
||||
const CACHE_NAME = 'gradle-user-home'
|
||||
const CACHE_PATH = [
|
||||
'~/.gradle/caches/*', // All directories in 'caches'
|
||||
'~/.gradle/notifications/*', // Prevent the re-rendering of first-use message for version
|
||||
|
@ -20,10 +15,8 @@ const CACHE_KEY = 'GUH_CACHE_KEY'
|
|||
const CACHE_RESULT = 'GUH_CACHE_RESULT'
|
||||
|
||||
export async function restore(): Promise<void> {
|
||||
if (!isCacheReadEnabled(CACHE_NAME)) return
|
||||
|
||||
if (gradleUserHomeExists()) {
|
||||
core.debug('Gradle User Home already exists. Not restoring from cache.')
|
||||
core.info('Gradle User Home already exists. Not restoring from cache.')
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -49,8 +42,6 @@ export async function restore(): Promise<void> {
|
|||
}
|
||||
|
||||
export async function save(): Promise<void> {
|
||||
if (!isCacheSaveEnabled(CACHE_NAME)) return
|
||||
|
||||
if (!gradleUserHomeExists()) {
|
||||
core.debug('No Gradle User Home to cache.')
|
||||
return
|
||||
|
|
|
@ -3,13 +3,8 @@ import fs from 'fs'
|
|||
|
||||
import * as core from '@actions/core'
|
||||
import * as cache from '@actions/cache'
|
||||
import {
|
||||
generateCacheKey,
|
||||
isCacheReadEnabled,
|
||||
isCacheSaveEnabled
|
||||
} from './cache-utils'
|
||||
import {generateCacheKey} from './cache-utils'
|
||||
|
||||
const CACHE_NAME = 'project-dot-gradle'
|
||||
const PATHS_TO_CACHE = [
|
||||
'configuration-cache' // Only configuration-cache is stored at present
|
||||
]
|
||||
|
@ -17,10 +12,8 @@ const CACHE_KEY = 'PROJECT_CACHE_KEY'
|
|||
const CACHE_RESULT = 'PROJECT_CACHE_RESULT'
|
||||
|
||||
export async function restore(rootDir: string): Promise<void> {
|
||||
if (!isCacheReadEnabled(CACHE_NAME)) return
|
||||
|
||||
if (projectDotGradleDirExists(rootDir)) {
|
||||
core.debug(
|
||||
core.info(
|
||||
'Project .gradle directory already exists. Not restoring from cache.'
|
||||
)
|
||||
return
|
||||
|
@ -46,8 +39,6 @@ export async function restore(rootDir: string): Promise<void> {
|
|||
}
|
||||
|
||||
export async function save(rootDir: string): Promise<void> {
|
||||
if (!isCacheSaveEnabled(CACHE_NAME)) return
|
||||
|
||||
if (!projectDotGradleDirExists(rootDir)) {
|
||||
core.debug('No project .gradle dir to cache.')
|
||||
return
|
||||
|
|
|
@ -1,26 +1,31 @@
|
|||
import * as cacheGradleUserHome from './cache-gradle-user-home'
|
||||
import * as cacheProjectDotGradle 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> {
|
||||
core.startGroup('Restore Gradle User Home from cache')
|
||||
await cacheGradleUserHome.restore()
|
||||
core.endGroup()
|
||||
if (!isCacheReadEnabled('gradle')) {
|
||||
core.debug('Cache read disabled')
|
||||
return
|
||||
}
|
||||
|
||||
core.startGroup('Restore project .gradle directory from cache')
|
||||
core.startGroup('Restore Gradle state from cache')
|
||||
await cacheGradleUserHome.restore()
|
||||
core.saveState(BUILD_ROOT_DIR, buildRootDirectory)
|
||||
await cacheProjectDotGradle.restore(buildRootDirectory)
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
export async function save(): Promise<void> {
|
||||
core.startGroup('Cache Gradle User Home')
|
||||
await cacheGradleUserHome.save()
|
||||
core.endGroup()
|
||||
if (!isCacheSaveEnabled('gradle')) {
|
||||
core.debug('Cache save disabled')
|
||||
return
|
||||
}
|
||||
|
||||
core.startGroup('Cache project .gradle directory')
|
||||
core.startGroup('Caching Gradle state')
|
||||
await cacheGradleUserHome.save()
|
||||
const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
|
||||
await cacheProjectDotGradle.save(buildRootDirectory)
|
||||
core.endGroup()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue