mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-26 11:02:10 +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
|
gradle-version: 6.9
|
||||||
build-root-directory: __tests__/samples/no-wrapper
|
build-root-directory: __tests__/samples/no-wrapper
|
||||||
arguments: help -DgradleVersionCheck=6.9
|
arguments: help -DgradleVersionCheck=6.9
|
||||||
gradle-user-home-cache-enabled: read-only
|
gradle-cache-enabled: read-only
|
||||||
project-dot-gradle-cache-enabled: read-only
|
|
||||||
- name: Test use Gradle version alias
|
- name: Test use Gradle version alias
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
gradle-version: release-candidate
|
gradle-version: release-candidate
|
||||||
build-root-directory: __tests__/samples/no-wrapper
|
build-root-directory: __tests__/samples/no-wrapper
|
||||||
arguments: help -DgradleVersionCheck=7.2
|
arguments: help -DgradleVersionCheck=7.2
|
||||||
gradle-user-home-cache-enabled: read-only
|
gradle-cache-enabled: read-only
|
||||||
project-dot-gradle-cache-enabled: read-only
|
|
||||||
- name: Test use defined Gradle executable
|
- name: Test use defined Gradle executable
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
gradle-executable: __tests__/samples/basic/gradlew${{ matrix.script-suffix }}
|
gradle-executable: __tests__/samples/basic/gradlew${{ matrix.script-suffix }}
|
||||||
build-root-directory: __tests__/samples/no-wrapper
|
build-root-directory: __tests__/samples/no-wrapper
|
||||||
arguments: help -DgradleVersionCheck=7.1.1
|
arguments: help -DgradleVersionCheck=7.1.1
|
||||||
gradle-user-home-cache-enabled: read-only
|
gradle-cache-enabled: read-only
|
||||||
project-dot-gradle-cache-enabled: read-only
|
|
||||||
|
|
||||||
# Test that the gradle-user-home cache will cache dependencies, by running build with --offline
|
# Test that the gradle-user-home cache will cache dependencies, by running build with --offline
|
||||||
dependencies-cache:
|
dependencies-cache:
|
||||||
|
@ -85,8 +82,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
build-root-directory: __tests__/samples/basic
|
build-root-directory: __tests__/samples/basic
|
||||||
arguments: test --offline
|
arguments: test --offline
|
||||||
gradle-user-home-cache-enabled: read-only
|
gradle-cache-enabled: read-only
|
||||||
project-dot-gradle-cache-enabled: read-only
|
|
||||||
|
|
||||||
# Test that the gradle-user-home cache will cache and restore local build-cache
|
# Test that the gradle-user-home cache will cache and restore local build-cache
|
||||||
build-cache:
|
build-cache:
|
||||||
|
@ -103,8 +99,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
build-root-directory: __tests__/samples/basic
|
build-root-directory: __tests__/samples/basic
|
||||||
arguments: test -DverifyCachedBuild=true
|
arguments: test -DverifyCachedBuild=true
|
||||||
gradle-user-home-cache-enabled: read-only
|
gradle-cache-enabled: read-only
|
||||||
project-dot-gradle-cache-enabled: read-only
|
|
||||||
|
|
||||||
# Test that the project-dot-gradle cache will cache and restore configuration-cache
|
# Test that the project-dot-gradle cache will cache and restore configuration-cache
|
||||||
configuration-cache:
|
configuration-cache:
|
||||||
|
@ -123,8 +118,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
build-root-directory: __tests__/samples/basic
|
build-root-directory: __tests__/samples/basic
|
||||||
arguments: test --configuration-cache
|
arguments: test --configuration-cache
|
||||||
gradle-user-home-cache-enabled: read-only
|
gradle-cache-enabled: read-only
|
||||||
project-dot-gradle-cache-enabled: read-only
|
|
||||||
|
|
||||||
# These build invocations are informational only, and are expected to fail
|
# These build invocations are informational only, and are expected to fail
|
||||||
failures:
|
failures:
|
||||||
|
@ -145,4 +139,4 @@ jobs:
|
||||||
with:
|
with:
|
||||||
build-root-directory: __tests__/samples/no-wrapper
|
build-root-directory: __tests__/samples/no-wrapper
|
||||||
arguments: help
|
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'.
|
description: Whether caching downloaded Gradle distributions is enabled or not. Valid values are 'true' (default), 'false', and 'read-only'.
|
||||||
required: false
|
required: false
|
||||||
default: true
|
default: true
|
||||||
gradle-user-home-cache-enabled:
|
gradle-cache-enabled:
|
||||||
description: Whether caching of state in Gradle User Home is enabled. Valid values are 'true' (default), 'false', and 'read-only'.
|
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
|
|
||||||
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'.
|
|
||||||
required: false
|
required: false
|
||||||
default: true
|
default: true
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,8 @@ import os from 'os'
|
||||||
|
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as cache from '@actions/cache'
|
import * as cache from '@actions/cache'
|
||||||
import {
|
import {generateCacheKey} from './cache-utils'
|
||||||
generateCacheKey,
|
|
||||||
isCacheReadEnabled,
|
|
||||||
isCacheSaveEnabled
|
|
||||||
} from './cache-utils'
|
|
||||||
|
|
||||||
const CACHE_NAME = 'gradle-user-home'
|
|
||||||
const CACHE_PATH = [
|
const CACHE_PATH = [
|
||||||
'~/.gradle/caches/*', // All directories in 'caches'
|
'~/.gradle/caches/*', // All directories in 'caches'
|
||||||
'~/.gradle/notifications/*', // Prevent the re-rendering of first-use message for version
|
'~/.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'
|
const CACHE_RESULT = 'GUH_CACHE_RESULT'
|
||||||
|
|
||||||
export async function restore(): Promise<void> {
|
export async function restore(): Promise<void> {
|
||||||
if (!isCacheReadEnabled(CACHE_NAME)) return
|
|
||||||
|
|
||||||
if (gradleUserHomeExists()) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,8 +42,6 @@ export async function restore(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function save(): Promise<void> {
|
export async function save(): Promise<void> {
|
||||||
if (!isCacheSaveEnabled(CACHE_NAME)) return
|
|
||||||
|
|
||||||
if (!gradleUserHomeExists()) {
|
if (!gradleUserHomeExists()) {
|
||||||
core.debug('No Gradle User Home to cache.')
|
core.debug('No Gradle User Home to cache.')
|
||||||
return
|
return
|
||||||
|
|
|
@ -3,13 +3,8 @@ import fs from 'fs'
|
||||||
|
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as cache from '@actions/cache'
|
import * as cache from '@actions/cache'
|
||||||
import {
|
import {generateCacheKey} from './cache-utils'
|
||||||
generateCacheKey,
|
|
||||||
isCacheReadEnabled,
|
|
||||||
isCacheSaveEnabled
|
|
||||||
} from './cache-utils'
|
|
||||||
|
|
||||||
const CACHE_NAME = 'project-dot-gradle'
|
|
||||||
const PATHS_TO_CACHE = [
|
const PATHS_TO_CACHE = [
|
||||||
'configuration-cache' // Only configuration-cache is stored at present
|
'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'
|
const CACHE_RESULT = 'PROJECT_CACHE_RESULT'
|
||||||
|
|
||||||
export async function restore(rootDir: string): Promise<void> {
|
export async function restore(rootDir: string): Promise<void> {
|
||||||
if (!isCacheReadEnabled(CACHE_NAME)) return
|
|
||||||
|
|
||||||
if (projectDotGradleDirExists(rootDir)) {
|
if (projectDotGradleDirExists(rootDir)) {
|
||||||
core.debug(
|
core.info(
|
||||||
'Project .gradle directory already exists. Not restoring from cache.'
|
'Project .gradle directory already exists. Not restoring from cache.'
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
@ -46,8 +39,6 @@ export async function restore(rootDir: string): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function save(rootDir: string): Promise<void> {
|
export async function save(rootDir: string): Promise<void> {
|
||||||
if (!isCacheSaveEnabled(CACHE_NAME)) return
|
|
||||||
|
|
||||||
if (!projectDotGradleDirExists(rootDir)) {
|
if (!projectDotGradleDirExists(rootDir)) {
|
||||||
core.debug('No project .gradle dir to cache.')
|
core.debug('No project .gradle dir to cache.')
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,26 +1,31 @@
|
||||||
import * as cacheGradleUserHome from './cache-gradle-user-home'
|
import * as cacheGradleUserHome from './cache-gradle-user-home'
|
||||||
import * as cacheProjectDotGradle from './cache-project-dot-gradle'
|
import * as cacheProjectDotGradle from './cache-project-dot-gradle'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
import {isCacheReadEnabled, isCacheSaveEnabled} from './cache-utils'
|
||||||
|
|
||||||
const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'
|
const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'
|
||||||
|
|
||||||
export async function restore(buildRootDirectory: string): Promise<void> {
|
export async function restore(buildRootDirectory: string): Promise<void> {
|
||||||
core.startGroup('Restore Gradle User Home from cache')
|
if (!isCacheReadEnabled('gradle')) {
|
||||||
await cacheGradleUserHome.restore()
|
core.debug('Cache read disabled')
|
||||||
core.endGroup()
|
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)
|
core.saveState(BUILD_ROOT_DIR, buildRootDirectory)
|
||||||
await cacheProjectDotGradle.restore(buildRootDirectory)
|
await cacheProjectDotGradle.restore(buildRootDirectory)
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function save(): Promise<void> {
|
export async function save(): Promise<void> {
|
||||||
core.startGroup('Cache Gradle User Home')
|
if (!isCacheSaveEnabled('gradle')) {
|
||||||
await cacheGradleUserHome.save()
|
core.debug('Cache save disabled')
|
||||||
core.endGroup()
|
return
|
||||||
|
}
|
||||||
|
|
||||||
core.startGroup('Cache project .gradle directory')
|
core.startGroup('Caching Gradle state')
|
||||||
|
await cacheGradleUserHome.save()
|
||||||
const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
|
const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
|
||||||
await cacheProjectDotGradle.save(buildRootDirectory)
|
await cacheProjectDotGradle.save(buildRootDirectory)
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
Loading…
Reference in a new issue