mirror of
https://github.com/gradle/actions
synced 2024-11-23 18:02:13 +00:00
Consolidate cache-enabled options
This commit is contained in:
parent
777a6fc967
commit
4d37378696
5 changed files with 26 additions and 49 deletions
20
.github/workflows/prod.yml
vendored
20
.github/workflows/prod.yml
vendored
|
@ -51,24 +51,21 @@ jobs:
|
|||
gradle-version: 6.9
|
||||
build-root-directory: __tests__/samples/no-wrapper
|
||||
arguments: help -DgradleVersionCheck=6.9
|
||||
gradle-user-home-cache-enabled: read-only
|
||||
project-dot-gradle-cache-enabled: read-only
|
||||
gradle-cache-enabled: read-only
|
||||
- name: Test use Gradle version alias
|
||||
uses: ./
|
||||
with:
|
||||
gradle-version: release-candidate
|
||||
build-root-directory: __tests__/samples/no-wrapper
|
||||
arguments: help -DgradleVersionCheck=7.2
|
||||
gradle-user-home-cache-enabled: read-only
|
||||
project-dot-gradle-cache-enabled: read-only
|
||||
gradle-cache-enabled: read-only
|
||||
- name: Test use defined Gradle executable
|
||||
uses: ./
|
||||
with:
|
||||
gradle-executable: __tests__/samples/basic/gradlew${{ matrix.script-suffix }}
|
||||
build-root-directory: __tests__/samples/no-wrapper
|
||||
arguments: help -DgradleVersionCheck=7.1.1
|
||||
gradle-user-home-cache-enabled: read-only
|
||||
project-dot-gradle-cache-enabled: read-only
|
||||
gradle-cache-enabled: read-only
|
||||
|
||||
# Test that the gradle-user-home cache will cache dependencies, by running build with --offline
|
||||
dependencies-cache:
|
||||
|
@ -85,8 +82,7 @@ jobs:
|
|||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test --offline
|
||||
gradle-user-home-cache-enabled: read-only
|
||||
project-dot-gradle-cache-enabled: read-only
|
||||
gradle-cache-enabled: read-only
|
||||
|
||||
# Test that the gradle-user-home cache will cache and restore local build-cache
|
||||
build-cache:
|
||||
|
@ -103,8 +99,7 @@ jobs:
|
|||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test -DverifyCachedBuild=true
|
||||
gradle-user-home-cache-enabled: read-only
|
||||
project-dot-gradle-cache-enabled: read-only
|
||||
gradle-cache-enabled: read-only
|
||||
|
||||
# Test that the project-dot-gradle cache will cache and restore configuration-cache
|
||||
configuration-cache:
|
||||
|
@ -123,8 +118,7 @@ jobs:
|
|||
with:
|
||||
build-root-directory: __tests__/samples/basic
|
||||
arguments: test --configuration-cache
|
||||
gradle-user-home-cache-enabled: read-only
|
||||
project-dot-gradle-cache-enabled: read-only
|
||||
gradle-cache-enabled: read-only
|
||||
|
||||
# These build invocations are informational only, and are expected to fail
|
||||
failures:
|
||||
|
@ -145,4 +139,4 @@ jobs:
|
|||
with:
|
||||
build-root-directory: __tests__/samples/no-wrapper
|
||||
arguments: help
|
||||
gradle-user-home-cache-enabled: no
|
||||
gradle-cache-enabled: no
|
||||
|
|
|
@ -20,12 +20,8 @@ inputs:
|
|||
description: Whether caching downloaded Gradle distributions is enabled or not. Valid values are 'true' (default), 'false', and 'read-only'.
|
||||
required: false
|
||||
default: true
|
||||
gradle-user-home-cache-enabled:
|
||||
description: Whether caching of state in Gradle User Home is enabled. Valid values are 'true' (default), 'false', and 'read-only'.
|
||||
required: false
|
||||
default: true
|
||||
project-dot-gradle-cache-enabled:
|
||||
description: Whether caching of state in project .gradle dir is enabled. Valid values are 'true' (default), 'false', and 'read-only'.
|
||||
gradle-cache-enabled:
|
||||
description: Whether caching of Gradle User Home and project .gradle directory is enabled. Valid values are 'true' (default), 'false', and 'read-only'.
|
||||
required: false
|
||||
default: true
|
||||
|
||||
|
|
|
@ -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…
Reference in a new issue