mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-12-25 14:36:19 +08:00
Initialize the Gradle User Home even when caching is disabled
This commit is contained in:
parent
97a4d7a5fd
commit
06d64212d3
@ -8,13 +8,22 @@ const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
|
|||||||
const CACHE_LISTENER = 'CACHE_LISTENER'
|
const CACHE_LISTENER = 'CACHE_LISTENER'
|
||||||
|
|
||||||
export async function restore(gradleUserHome: string): Promise<void> {
|
export async function restore(gradleUserHome: string): Promise<void> {
|
||||||
if (!shouldRestoreCaches()) {
|
// Only restore cache on first action step in workflow.
|
||||||
|
if (process.env[CACHE_RESTORED_VAR]) {
|
||||||
|
core.info('Cache only restored on first action step.')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
core.exportVariable(CACHE_RESTORED_VAR, true)
|
||||||
|
|
||||||
|
// Initialize the Gradle User Home even when caching is disabled.
|
||||||
const gradleStateCache = new GradleStateCache(gradleUserHome)
|
const gradleStateCache = new GradleStateCache(gradleUserHome)
|
||||||
gradleStateCache.init()
|
gradleStateCache.init()
|
||||||
|
|
||||||
|
if (isCacheDisabled()) {
|
||||||
|
core.info('Cache is disabled: will not restore state from previous builds.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await core.group('Restore Gradle state from cache', async () => {
|
await core.group('Restore Gradle state from cache', async () => {
|
||||||
core.saveState(GRADLE_USER_HOME, gradleUserHome)
|
core.saveState(GRADLE_USER_HOME, gradleUserHome)
|
||||||
|
|
||||||
@ -24,8 +33,6 @@ export async function restore(gradleUserHome: string): Promise<void> {
|
|||||||
core.saveState(CACHE_LISTENER, cacheListener.stringify())
|
core.saveState(CACHE_LISTENER, cacheListener.stringify())
|
||||||
})
|
})
|
||||||
|
|
||||||
// Export var that is detected in all later restore steps
|
|
||||||
core.exportVariable(CACHE_RESTORED_VAR, true)
|
|
||||||
// Export state that is detected in corresponding post-action step
|
// Export state that is detected in corresponding post-action step
|
||||||
core.saveState(CACHE_RESTORED_VAR, true)
|
core.saveState(CACHE_RESTORED_VAR, true)
|
||||||
}
|
}
|
||||||
@ -51,19 +58,6 @@ export async function save(): Promise<void> {
|
|||||||
logCachingReport(cacheListener)
|
logCachingReport(cacheListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldRestoreCaches(): boolean {
|
|
||||||
if (isCacheDisabled()) {
|
|
||||||
core.info('Cache is disabled: will not restore state from previous builds.')
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env[CACHE_RESTORED_VAR]) {
|
|
||||||
core.info('Cache only restored on first action step.')
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldSaveCaches(): boolean {
|
function shouldSaveCaches(): boolean {
|
||||||
if (isCacheDisabled()) {
|
if (isCacheDisabled()) {
|
||||||
core.info('Cache is disabled: will not save state for later builds.')
|
core.info('Cache is disabled: will not save state for later builds.')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user